HLE: handle WM_CLOSE alongside WM_SYSCOMMAND/SC_CLOSE in lifecycle (#168) #208

Open
AscilCH wants to merge 1 commit from upstream-pr/208 into main
AscilCH commented 2026-11-24 22:33:57 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-24T22:33:57Z.


Problem

Fixes the WM_CLOSE issue reported in #168:

taskkill without /F sends WM_CLOSE. The title's window went away, but the lifecycle hook only ends the title on WM_SYSCOMMAND/SC_CLOSE, so the process kept running and rendering with no window for an hour until I killed it.

In crates/victory-hle/src/modules/lifecycle.rs, window_proc only intercepted WM_SYSCOMMAND with SC_CLOSE. When WM_CLOSE is 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

  • Intercept wm::WM_CLOSE alongside wm::WM_SYSCOMMAND/wm::SC_CLOSE in window_proc (is_close_message) to call end_title("window closed", ...) and return 0 (end_title is already idempotent via ENDING).
  • Added a unit test verifying WM_CLOSE and WM_SYSCOMMAND/SC_CLOSE are recognised as close requests while other messages (such as SC_MINIMIZE) are not, and verifying WM_CLOSE does not reach the title's window procedure or destroy the window.

Verification

  • rustfmt --edition 2024 --check crates/victory-hle/src/modules/lifecycle.rs: clean
  • cargo test -p victory-hle --locked lifecycle: passed
  • cargo xtask policy: 169 files ok
  • cargo clippy -p victory-hle --all-targets --locked -- -D warnings: clean
  • cargo clippy -p victory-hle --all-targets --all-features --locked -- -D warnings: clean

(AI-assisted; synthetic unit tests only, no game data.)

<!-- greyfinch-sync:fxceless/victory-fork:issue:5481457720 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/208). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-24T22:33:57Z. --- ## Problem Fixes the `WM_CLOSE` issue reported in #168: > `taskkill` without `/F` sends `WM_CLOSE`. The title's window went away, but the lifecycle hook only ends the title on `WM_SYSCOMMAND`/`SC_CLOSE`, so the process kept running and rendering with no window for an hour until I killed it. In `crates/victory-hle/src/modules/lifecycle.rs`, `window_proc` only intercepted `WM_SYSCOMMAND` with `SC_CLOSE`. When `WM_CLOSE` is 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 - Intercept `wm::WM_CLOSE` alongside `wm::WM_SYSCOMMAND`/`wm::SC_CLOSE` in `window_proc` (`is_close_message`) to call `end_title("window closed", ...)` and return `0` (`end_title` is already idempotent via `ENDING`). - Added a unit test verifying `WM_CLOSE` and `WM_SYSCOMMAND`/`SC_CLOSE` are recognised as close requests while other messages (such as `SC_MINIMIZE`) are not, and verifying `WM_CLOSE` does not reach the title's window procedure or destroy the window. ## Verification - `rustfmt --edition 2024 --check crates/victory-hle/src/modules/lifecycle.rs`: clean - `cargo test -p victory-hle --locked lifecycle`: passed - `cargo xtask policy`: 169 files ok - `cargo clippy -p victory-hle --all-targets --locked -- -D warnings`: clean - `cargo clippy -p victory-hle --all-targets --all-features --locked -- -D warnings`: clean *(AI-assisted; synthetic unit tests only, no game data.)*
rafaconvaitis commented 2026-11-25 23:09:57 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7176690405 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/208#issuecomment-7176690405). Originally posted by [rafaconvaitis](https://github.com/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.
CwWwWwW commented 2026-11-27 13:19:47 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by CwWwWwW on 2026-11-27T13:19:47Z.


Thanks for fixing #168 — the direct WM_CLOSE hole is real and worth closing.

One risk in the current shape: is_close_message treats every WM_CLOSE on any hooked window as the user closing the title. Windows titles (this one included) also close their own helper/dialog/child/hidden windows with WM_CLOSE (PostMessage(hwnd, WM_CLOSE, 0, 0) is the usual way to end a dialog loop). With this patch such a call would run end_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_CLOSE only 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/gtafl0p research 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.txt

So I'd suggest:

  • keep the WM_SYSCOMMAND/SC_CLOSE branch as is;
  • end the title only for a direct WM_CLOSE when the window is a visible top-level owner (IsWindowVisible and GetAncestor(GA_ROOTOWNER) == hwnd) — that still covers taskkill without /F and Task Manager's End task, which post WM_CLOSE to the main window;
  • forward WM_CLOSE from hidden/child/owned windows to the title's procedure as today, and extend the regression test with that case (hidden window: message reaches recording/DefWindowProcW and the process stays up; visible main window: intercepted).

Happy to help re-test if useful — no code attached, just the review point.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7219343878 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/208#issuecomment-7219343878). Originally posted by [CwWwWwW](https://github.com/CwWwWwW) on 2026-11-27T13:19:47Z. --- Thanks for fixing #168 — the direct `WM_CLOSE` hole is real and worth closing. One risk in the current shape: `is_close_message` treats **every** `WM_CLOSE` on any hooked window as the user closing the title. Windows titles (this one included) also close their own **helper/dialog/child/hidden** windows with `WM_CLOSE` (`PostMessage(hwnd, WM_CLOSE, 0, 0)` is the usual way to end a dialog loop). With this patch such a call would run `end_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_CLOSE` only 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/gtafl0p` research 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.txt So I'd suggest: - keep the `WM_SYSCOMMAND`/`SC_CLOSE` branch as is; - end the title only for a direct `WM_CLOSE` when the window is a visible top-level owner (`IsWindowVisible` and `GetAncestor(GA_ROOTOWNER) == hwnd`) — that still covers `taskkill` without `/F` and Task Manager's End task, which post `WM_CLOSE` to the main window; - forward `WM_CLOSE` from hidden/child/owned windows to the title's procedure as today, and extend the regression test with that case (hidden window: message reaches `recording`/`DefWindowProcW` and the process stays up; visible main window: intercepted). Happy to help re-test if useful — no code attached, just the review point.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/208:upstream-pr/208'
git switch 'upstream-pr/208'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/208'
git switch 'upstream-pr/208'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/208'
git switch 'upstream-pr/208'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/208'
git switch 'main'
git merge --squash 'upstream-pr/208'
git switch 'main'
git merge --ff-only 'upstream-pr/208'
git switch 'main'
git merge 'upstream-pr/208'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
fxceless/victory-fork!208
No description provided.