Skip to content

Commit 0a13553

Browse files
committed
Fix GUI exit
1 parent 5514a0b commit 0a13553

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

gnwinfo/context.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ gnwinfo_ctx_init(HINSTANCE inst, HWND wnd, struct nk_context* ctx, float width,
324324
InitializeSRWLock(&g_ctx.lock);
325325
g_ctx.update_mask = 0;
326326
g_ctx.update_stop = 0;
327+
g_ctx.exit_pending = 0;
327328
g_ctx.update_event = CreateEventW(NULL, FALSE, FALSE, NULL);
328329
if (g_ctx.update_event)
329330
g_ctx.update_thread = CreateThread(NULL, 0, gnwinfo_ctx_update_thread, NULL, 0, NULL);

gnwinfo/gnwinfo.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ wWinMain(_In_ HINSTANCE hInstance,
292292
nk_input_end(ctx);
293293

294294
/* GUI */
295-
AcquireSRWLockShared(&g_ctx.lock);
295+
AcquireSRWLockExclusive(&g_ctx.lock);
296296
if (g_ctx.window_flag & GUI_WINDOW_SETTINGS)
297297
gnwinfo_set_style(ctx);
298298
gnwinfo_draw_main_window(ctx, g_ctx.gui_width, g_ctx.gui_height);
@@ -305,7 +305,9 @@ wWinMain(_In_ HINSTANCE hInstance,
305305
gnwinfo_draw_display_window(ctx, g_ctx.gui_width, g_ctx.gui_height);
306306
gnwinfo_draw_mm_window(ctx, g_ctx.gui_width, g_ctx.gui_height);
307307
gnwinfo_draw_hostname_window(ctx, g_ctx.gui_width, g_ctx.gui_height);
308-
ReleaseSRWLockShared(&g_ctx.lock);
308+
ReleaseSRWLockExclusive(&g_ctx.lock);
309+
if (g_ctx.exit_pending)
310+
gnwinfo_ctx_exit();
309311

310312
/* Draw */
311313
nk_gdip_render(g_ctx.gui_aa, g_color_back);

gnwinfo/gnwinfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ typedef struct _GNW_CONTEXT
160160
HANDLE update_thread;
161161
volatile LONG update_mask;
162162
volatile LONG update_stop;
163+
volatile LONG exit_pending;
163164
} GNW_CONTEXT;
164165
extern GNW_CONTEXT g_ctx;
165166

gnwinfo/summary.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,8 @@ gnwinfo_draw_main_window(struct nk_context* ctx, float width, float height)
784784
nk_image_id(0), GET_PNG(IDR_PNG_CLOSE)))
785785
{
786786
nk_end(ctx);
787-
gnwinfo_ctx_exit();
787+
InterlockedExchange(&g_ctx.exit_pending, 1);
788+
return;
788789
}
789790

790791
nk_layout_row_begin(ctx, NK_DYNAMIC, 0, 4);
@@ -808,7 +809,7 @@ gnwinfo_draw_main_window(struct nk_context* ctx, float width, float height)
808809
g_ctx.window_flag |= GUI_WINDOW_ABOUT;
809810
nk_layout_row_push(ctx, g_ctx.gui_ratio);
810811
if (nk_button_image_hover(ctx, GET_PNG(IDR_PNG_CLOSE), N_(N__CLOSE)))
811-
gnwinfo_ctx_exit();
812+
InterlockedExchange(&g_ctx.exit_pending, 1);
812813
nk_layout_row_end(ctx);
813814

814815
if (g_ctx.main_flag & MAIN_INFO_OS)

0 commit comments

Comments
 (0)