From bcffd702700100f69beed21a73fccc84906cd982 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Thu, 8 Jul 2021 14:05:42 +1000 Subject: [PATCH] [client] app: init/destroy imgui context on run/shutdown --- client/src/main.c | 24 +++++++++++------------- client/src/main.h | 4 ++++ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/client/src/main.c b/client/src/main.c index 097a9d61..0159b521 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -56,8 +56,6 @@ #include "ll.h" #include "egl_dynprocs.h" -#include "cimgui.h" - // forwards static int cursorThread(void * unused); static int renderThread(void * unused); @@ -99,21 +97,12 @@ static void lgInit(void) static int renderThread(void * unused) { - /* setup imgui */ - igCreateContext(NULL); - ImGuiIO * io = igGetIO(); - unsigned char *text_pixels = NULL; - int text_w, text_h; - ImFontAtlas_GetTexDataAsRGBA32(io->Fonts, &text_pixels, - &text_w, &text_h, NULL); - if (!g_state.lgr->render_startup(g_state.lgrData)) { g_state.state = APP_STATE_SHUTDOWN; /* unblock threads waiting on the condition */ lgSignalEvent(e_startup); - igDestroyContext(NULL); return 1; } @@ -144,7 +133,7 @@ static int renderThread(void * unused) .x = g_state.windowW, .y = g_state.windowH }; - io->DisplaySize = displaySize; + g_state.io->DisplaySize = displaySize; if (g_state.lgr) g_state.lgr->on_resize(g_state.lgrData, g_state.windowW, g_state.windowH, @@ -211,7 +200,6 @@ static int renderThread(void * unused) g_state.lgr = NULL; LG_LOCK_FREE(g_state.lgrLock); - igDestroyContext(NULL); return 0; } @@ -701,6 +689,14 @@ static int lg_run(void) g_state.showFPS = g_params.showFPS; + /* setup imgui */ + igCreateContext(NULL); + g_state.io = igGetIO(); + unsigned char *text_pixels = NULL; + int text_w, text_h; + ImFontAtlas_GetTexDataAsRGBA32(g_state.io->Fonts, &text_pixels, + &text_w, &text_h, NULL); + // search for the best displayserver ops to use for(int i = 0; i < LG_DISPLAYSERVER_COUNT; ++i) if (LG_DisplayServers[i]->probe()) @@ -1067,6 +1063,8 @@ static void lg_shutdown(void) g_state.ds->free(); ivshmemClose(&g_state.shm); + + igDestroyContext(NULL); } int main(int argc, char * argv[]) diff --git a/client/src/main.h b/client/src/main.h index 20938f8f..9c7c239b 100644 --- a/client/src/main.h +++ b/client/src/main.h @@ -33,6 +33,8 @@ #include "spice/spice.h" #include +#include "cimgui.h" + enum RunState { APP_STATE_RUNNING, @@ -44,6 +46,8 @@ struct AppState { enum RunState state; + ImGuiIO * io; + struct LG_DisplayServerOps * ds; bool dsInitialized;