d3d12_xs: closing the game window ends the title #154

Closed
github-bot wants to merge 1 commit from gh-pr/154/head into gh-pr/154/base
Owner

@⁠GDAgent on GitHub · 2026-11-22 16:20 UTC · original
GDAgent:port/d3d12-window-close → main · +123 −1 · 2 files · 1 commits · closed without merging

Library / area: d3d12_xs (present.rs, title window and host window)

Exports changed (exports.txt rows): none

Source of the behaviour: console titles have no reason to handle WM_CLOSE; quitting a game on the console ends the title process. Ported from brcly/TomBox PR #12 (GDAgent; crates declare MIT OR Apache-2.0).

A title that presents into its own window ignores WM_CLOSE, so the close button and Alt+F4 do nothing. The host window (XboxEmulatorHostWindow) passes WM_CLOSE to DefWindowProc, which destroys the window and leaves the title running without one.

Changes:

  • The title window found by find_title_window is subclassed (SetWindowLongPtrW(GWLP_WNDPROC)) for WM_CLOSE only. Every other message reaches the title's procedure through CallWindowProcW, with its result. The hook is installed once.
  • WM_CLOSE on either window logs close requested: ending the title and calls TerminateProcess(self, 0).
  • The title gets no suspend notification first, so unsaved progress is lost. Delivering a PLM suspend before ending (os_host::plm::suspend) would be possible, but WM_CLOSE arrives on the title's window thread, which is often the thread its suspend handler waits for. Left out to avoid a deadlock; open to discussion.

Tests: present::close_tests::close_message_ends_the_title_process runs the scenario in a child process (the test binary re-run with an env marker):

  • a window whose procedure ignores WM_CLOSE gets hooked;
  • a custom message still reaches it and returns its result;
  • posting WM_CLOSE ends the child with exit code 0 before the harness prints its summary.

Every other path exits non-zero.

cargo test --release -p d3d12_xs --lib: 477 passed, 4 failed, 39 ignored. The 4 failures also occur on plain main (alias::tests::msaa_depth_with_a_larger_pc_layout_never_overlaps_the_next_title_placement, placed_offset::tests::uneven_views_get_exact_helpers_and_msaa_shares_the_alias_heap, title_shadow::tests::buffer_then_texture_migrates_to_one_local_heap_and_keeps_bytes, xs_exports::console_fixed_tests::fixed_result_dxgix_exports_match_every_console_d3d12_xs) and are unrelated to this change.

  • Native Windows 11; not run under Proton. Not verified in a title with this repo's build; the scenario test above runs against a real window.

  • cargo test -p d3d12_xs passes (the 4 failures also occur on main)

  • No game or console files and no binaries included

  • No fake success; anything not possible is left missing with a note

**@⁠GDAgent** on GitHub · 2026-11-22 16:20 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/154) `GDAgent:port/d3d12-window-close` → `main` · +123 −1 · 2 files · 1 commits · closed without merging **Library / area:** d3d12_xs (`present.rs`, title window and host window) **Exports changed (exports.txt rows):** none **Source of the behaviour:** console titles have no reason to handle `WM_CLOSE`; quitting a game on the console ends the title process. Ported from brcly/TomBox PR #12 (GDAgent; crates declare MIT OR Apache-2.0). A title that presents into its own window ignores `WM_CLOSE`, so the close button and Alt+F4 do nothing. The host window (`XboxEmulatorHostWindow`) passes `WM_CLOSE` to `DefWindowProc`, which destroys the window and leaves the title running without one. Changes: - The title window found by `find_title_window` is subclassed (`SetWindowLongPtrW(GWLP_WNDPROC)`) for `WM_CLOSE` only. Every other message reaches the title's procedure through `CallWindowProcW`, with its result. The hook is installed once. - `WM_CLOSE` on either window logs `close requested: ending the title` and calls `TerminateProcess(self, 0)`. - The title gets no suspend notification first, so unsaved progress is lost. Delivering a PLM suspend before ending (`os_host::plm::suspend`) would be possible, but `WM_CLOSE` arrives on the title's window thread, which is often the thread its suspend handler waits for. Left out to avoid a deadlock; open to discussion. Tests: `present::close_tests::close_message_ends_the_title_process` runs the scenario in a child process (the test binary re-run with an env marker): - a window whose procedure ignores `WM_CLOSE` gets hooked; - a custom message still reaches it and returns its result; - posting `WM_CLOSE` ends the child with exit code 0 before the harness prints its summary. Every other path exits non-zero. `cargo test --release -p d3d12_xs --lib`: 477 passed, 4 failed, 39 ignored. The 4 failures also occur on plain `main` (`alias::tests::msaa_depth_with_a_larger_pc_layout_never_overlaps_the_next_title_placement`, `placed_offset::tests::uneven_views_get_exact_helpers_and_msaa_shares_the_alias_heap`, `title_shadow::tests::buffer_then_texture_migrates_to_one_local_heap_and_keeps_bytes`, `xs_exports::console_fixed_tests::fixed_result_dxgix_exports_match_every_console_d3d12_xs`) and are unrelated to this change. - Native Windows 11; not run under Proton. Not verified in a title with this repo's build; the scenario test above runs against a real window. - [x] `cargo test -p d3d12_xs` passes (the 4 failures also occur on `main`) - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note
Console titles have no reason to handle WM_CLOSE. A title that presents
into its own window ignores it, so the window cannot be closed, and the
host window's DefWindowProc destroys the window but leaves the title
running without one. As quitting a game does on the console, WM_CLOSE
(close button, Alt+F4) now ends the process with a log line: the title's
window procedure is subclassed for this one message only, and the host
window handles it the same way. The title gets no suspend or exit
notification first, so unsaved progress is lost.

The test runs the scenario in a child process: a window whose procedure
ignores WM_CLOSE is hooked, other messages still reach it with their
result, and posting WM_CLOSE ends the child with exit code 0 before the
test harness can print its summary.

Ported from brcly/TomBox PR #12 (GDAgent, MIT OR Apache-2.0).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:12:01 +00:00
github-bot closed this pull request 2026-11-26 06:12:01 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 16:28 UTC · original

Applied in 1570be5 (merged in 604b5a1) with your authorship kept, thanks! I removed one trailing // comment in the test, and fixed a conflict in THIRD_PARTY/CREDITS with #151 by keeping both additions on the TomBox line.

**@⁠omonkeyz** on GitHub · 2026-11-22 16:28 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/154#issuecomment-7082095663) Applied in 1570be5 (merged in 604b5a1) with your authorship kept, thanks! I removed one trailing `//` comment in the test, and fixed a conflict in THIRD_PARTY/CREDITS with #151 by keeping both additions on the TomBox line.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.