diff --git a/titlebar.c.v b/titlebar.c.v index 8bc201f..a8a7a31 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)) + } } }