From 35f949aa140ce4e478faec71ee37848ce66e984d Mon Sep 17 00:00:00 2001 From: Marten Hildell Date: Sun, 14 Jun 2026 16:35:04 +0200 Subject: [PATCH] fix(windows): guard titlebar_dark with sapp.isvalid() titlebar_dark() calls sapp.win32_get_hwnd(), which asserts _sapp.valid and aborts if sokol_app hasn't been initialised yet. set_theme() (and any early dark/light toggle) can run before sapp.run(), so on Windows the app aborts at startup before the window opens. Guard the DwmSetWindowAttribute call with sapp.isvalid() so an early call is a harmless no-op; once the window is up the attribute is applied exactly as before. Found bringing up vlang/gui on native Windows, but it's a real ordering bug independent of toolchain (reproduces under mingw-w64/gcc and MSVC). --- titlebar.c.v | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/titlebar.c.v b/titlebar.c.v index 8bc201fe..a8a7a310 100644 --- a/titlebar.c.v +++ b/titlebar.c.v @@ -22,6 +22,10 @@ fn C.DwmSetWindowAttribute(voidptr, u32, &u8, u32) // titlebar_dark set the window titlebar to be dark or light, api is from dwmapi.h, windows 10+ only pub fn titlebar_dark(dark bool) { $if windows { - C.DwmSetWindowAttribute(sapp.win32_get_hwnd(), 20, &dark, sizeof(dark)) + // set_theme() can run before sapp.run(); win32_get_hwnd() then + // aborts on `_sapp.valid`. Guard with isvalid(). + if sapp.isvalid() { + C.DwmSetWindowAttribute(sapp.win32_get_hwnd(), 20, &dark, sizeof(dark)) + } } }