Skip to content

fix(windows): guard titlebar_dark with sapp.isvalid()#60

Open
MartenH wants to merge 1 commit into
vlang:mainfrom
MartenH:fix/windows-titlebar-before-sapp-run
Open

fix(windows): guard titlebar_dark with sapp.isvalid()#60
MartenH wants to merge 1 commit into
vlang:mainfrom
MartenH:fix/windows-titlebar-before-sapp-run

Conversation

@MartenH

@MartenH MartenH commented Jun 14, 2026

Copy link
Copy Markdown

Found while bringing up vlang/gui on native Windows, but it's a real ordering bug independent of toolchain (reproduces under both mingw-w64/gcc and MSVC).

titlebar_dark() calls sapp.win32_get_hwnd(), which asserts _sapp.valid and aborts if sokol_app hasn't been initialised yet:

titlebar_dark() -> win32_get_hwnd() -> abort on _sapp.valid

set_theme() (and any early dark/light toggle) can run before sapp.run(), so on Windows the app aborts at startup before the window even opens.

This guards the DwmSetWindowAttribute call with sapp.isvalid(), so an early call is a harmless no-op; once the window is up the titlebar attribute is applied exactly as before.

pub fn titlebar_dark(dark bool) {
	$if windows {
		if sapp.isvalid() {
			C.DwmSetWindowAttribute(sapp.win32_get_hwnd(), 20, &dark, sizeof(dark))
		}
	}
}

v fmt-clean. Verified on native Windows (mingw-w64 and MSVC builds both start cleanly with the guard).

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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant