Run the window's close on a thread of its own and hide the window, so it keeps answering while the game saves.

gfx_window_win.c wnd_proc ran gfx_window_closed, which does not return, on the window thread for WM_CLOSE and
WM_ENDSESSION. While pipeline builds run the end takes seconds (vk_pipeline_save_exit waits up to 5 s), and the
window stopped pumping meanwhile: after 5 s Windows showed it as not responding, and an "End task" there killed
the process in the middle of its saves.

WM_CLOSE now starts an "exit" thread that runs gfx_window_closed (exit_start; the end runs on the window thread as
before should no thread be made) and returns 0, so the pump goes on. The window is hidden as the end starts, so a
window that still answers does not invite a second close; one would find the end under way in rt_exit_begin.
WM_ENDSESSION(TRUE) starts the same thread and waits for it on the window thread, since Windows ends the process
once that message returns; after a close had started the end it waits as well. The SDL window is unchanged.
ShutdownBlockReasonCreate was left out: called at WM_ENDSESSION it is too late to show a reason.

Not reproduced before the change (a play-test item: close on the boot screen, the window must not ghost).
tests/exit_order_check.py checks statically that WM_CLOSE and WM_ENDSESSION go through exit_start, which hides the
window, and that the session's end joins the thread; it and the compile checks pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-13 17:43:36 -05:00
parent f9033dce64
commit dc94771051
2 changed files with 42 additions and 5 deletions

View File

@@ -161,6 +161,17 @@ def static_checks():
ok = None not in pos and pos == sorted(pos)
print(f'cheats.c rebuild_if_needed: {", ".join(want)} in that order: {"ok" if ok else "FAIL " + str(pos)}', flush=True)
bad += not ok
# the window's close runs the end on a thread of its own, and the session's end waits for it
win = strip_comments((RT / 'gfx_window_win.c').read_text(encoding='utf-8'))
proc = function(win, 'static LRESULT CALLBACK wnd_proc(')
close = proc[proc.index('case WM_CLOSE:'):]
close = close[:close.index('case WM_ERASEBKGND:')]
session = proc[proc.index('case WM_ENDSESSION:'):proc.index('case WM_CLOSE:')]
ok = ('exit_start(' in close and 'gfx_window_closed(' not in close and 'exit_start(' in session
and 'plat_thread_join(' in session and 'ShowWindow(h, SW_HIDE)' in function(win, 'static PlatThread *exit_start('))
print(f'gfx_window_win.c: WM_CLOSE and WM_ENDSESSION start the end on its own thread and hide the window: '
f'{"ok" if ok else "FAIL"}', flush=True)
bad += not ok
steps = function(gp, 'void rt_exit_steps(unsigned what)')
pos = calls_in_order(steps, ['rtss_limit_restore', 'vk_pipeline_save_exit'])
ok = None not in pos and pos[0] < pos[1]