HLE: handle WM_CLOSE alongside WM_SYSCOMMAND/SC_CLOSE in lifecycle (#168) #208
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/208"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-24T22:33:57Z.
Problem
Fixes the
WM_CLOSEissue reported in #168:In
crates/victory-hle/src/modules/lifecycle.rs,window_proconly interceptedWM_SYSCOMMANDwithSC_CLOSE. WhenWM_CLOSEis sent directly to the window (e.g.taskkill, Task Manager "End task", or automated scripts), it passed through to the title's procedure /DefWindowProcW, which destroys the window without suspending or terminating the title process.Fix
wm::WM_CLOSEalongsidewm::WM_SYSCOMMAND/wm::SC_CLOSEinwindow_proc(is_close_message) to callend_title("window closed", ...)and return0(end_titleis already idempotent viaENDING).WM_CLOSEandWM_SYSCOMMAND/SC_CLOSEare recognised as close requests while other messages (such asSC_MINIMIZE) are not, and verifyingWM_CLOSEdoes not reach the title's window procedure or destroy the window.Verification
rustfmt --edition 2024 --check crates/victory-hle/src/modules/lifecycle.rs: cleancargo test -p victory-hle --locked lifecycle: passedcargo xtask policy: 169 files okcargo clippy -p victory-hle --all-targets --locked -- -D warnings: cleancargo clippy -p victory-hle --all-targets --all-features --locked -- -D warnings: clean(AI-assisted; synthetic unit tests only, no game data.)
Imported from fxceless/victory-fork. Originally posted by rafaconvaitis on 2026-11-25T22:42:21Z.
Native Windows validation on the pinned Flamingo 63d976b base. In the previous local build, .NET Process.CloseMainWindow left the game process running. The same process and window handled the SC_CLOSE path when posted directly.
Adding the WM_CLOSE predicate here caused CloseMainWindow to enter the existing lifecycle and exit without termination from the wrapper, with two suspend routines registered. That first test still reached the existing suspend deadline. I then included Marvisak #1080 for constrained notifications before suspend. At the live title window during startup, the same CloseMainWindow request logged one constrained routine, two suspend routines, and "title suspended; ending the title" about 98 ms after entering the lifecycle. The process was observed exited in 1.23 seconds without a forced stop. The five lifecycle tests passed with the combined fix.
Imported from fxceless/victory-fork. Originally posted by CwWwWwW on 2026-11-27T13:19:47Z.
Thanks for fixing #168 — the direct
WM_CLOSEhole is real and worth closing.One risk in the current shape:
is_close_messagetreats everyWM_CLOSEon any hooked window as the user closing the title. Windows titles (this one included) also close their own helper/dialog/child/hidden windows withWM_CLOSE(PostMessage(hwnd, WM_CLOSE, 0, 0)is the usual way to end a dialog loop). With this patch such a call would runend_title: the suspend routines run and the whole process terminates — a spurious shutdown of the game, which is a regression compared with today's behaviour for those windows (SC_CLOSEonly arrives on user-initiated closes of the active/top-level window).Evidence from fork-network research (not a code suggestion, just what another field integration of this same title found): the
asucodes/gtafl0presearch fork (RTX 4050, inherited from this fork) has a field-tested variant of this fix that narrows the direct close to the main window and forwards hidden/child/owned windows to the title as before —message == WM_CLOSE && IsWindowVisible(hwnd) && GetAncestor(hwnd, GA_ROOTOWNER) == hwnd. Its README's "Window shutdown and memory mirrors" section reports a live run exiting cleanly with that condition. Patch (research evidence only, not to port): https://github.com/asucodes/gtafl0p/blob/main/patches/vi-4050-nvidia.diff.txtSo I'd suggest:
WM_SYSCOMMAND/SC_CLOSEbranch as is;WM_CLOSEwhen the window is a visible top-level owner (IsWindowVisibleandGetAncestor(GA_ROOTOWNER) == hwnd) — that still coverstaskkillwithout/Fand Task Manager's End task, which postWM_CLOSEto the main window;WM_CLOSEfrom hidden/child/owned windows to the title's procedure as today, and extend the regression test with that case (hidden window: message reachesrecording/DefWindowProcWand the process stays up; visible main window: intercepted).Happy to help re-test if useful — no code attached, just the review point.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.