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

Open
github-bot wants to merge 1 commit from github-bot/gh-208 into main AGit
Owner

@⁠AscilCH on GitHub · 2026-11-24 22:33 UTC · original
AscilCH:fix/lifecycle-handle-wm-close → main · +85 −3 · 1 files · 1 commits · open

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.)

**@⁠AscilCH** on GitHub · 2026-11-24 22:33 UTC · [original](https://github.com/fxceless/victory-fork/pull/208) `AscilCH:fix/lifecycle-handle-wm-close` → `main` · +85 −3 · 1 files · 1 commits · open ## 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.)*
`window_proc` in `crates/victory-hle/src/modules/lifecycle.rs` only
intercepted `WM_SYSCOMMAND`/`SC_CLOSE` (close button / Alt+F4). When
`taskkill` (without `/F`), Task Manager, or an automation script sends
`WM_CLOSE` directly to the window, the message passed through to
`DefWindowProcW`, destroying the window while leaving the title process
running and rendering headless.

Intercept `WM_CLOSE` alongside `WM_SYSCOMMAND`/`SC_CLOSE` to suspend and
exit the title cleanly (`end_title` is already idempotent). Add a unit
test verifying `WM_CLOSE` is recognised as a close request and never
reaches the title's window procedure.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:38:20 +00:00
Author
Owner

@⁠rafaconvaitis on GitHub · 2026-11-25 22:42 UTC · original

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.

**@⁠rafaconvaitis** on GitHub · 2026-11-25 22:42 UTC · [original](https://github.com/fxceless/victory-fork/pull/208#issuecomment-7176690405) 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/208/head:github-bot/gh-208'
git switch 'github-bot/gh-208'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-208'
git switch 'github-bot/gh-208'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-208'
git switch 'github-bot/gh-208'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-208'
git switch 'main'
git merge --squash 'github-bot/gh-208'
git switch 'main'
git merge --ff-only 'github-bot/gh-208'
git switch 'main'
git merge 'github-bot/gh-208'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.