Clear stale button and key state in GameInput output buffers #2715
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2715
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2715"
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?
@VlREX on GitHub · 2026-11-25 18:41 UTC · original
VlREX:fix/gameinput-stale-state→main· +46 −11 · 1 files · 1 commits · openGetGamepadState must return an at-rest state and false for readings without gamepad input. GetKeyState uses a zero scan code and virtual key to mark the end of valid keys when the output has room. Implement both for reused output buffers. Regression tests start with a pressed button/trigger or a nonzero key in the output and cover a full buffer, spare space, and an empty list. Both tests failed before the fix. Nine input tests passed locally using the fake host, excluding the native host and export resolver. References: GetGamepadState and GetKeyState.
github-bot referenced this pull request2026-11-26 05:12:40 +00:00
@kotekompotek on GitHub · 2026-11-25 18:51 UTC · original
Matches the documented contract on both sides: GetKeyState writes a zeroed entry after the last valid key when the buffer has room (the terminator titles scan for), and GetGamepadState returns false but still writes an at-rest state for non-gamepad readings. The reused-buffer regression is the right way to catch stale-state bugs.
@oni-swr on GitHub · 2026-11-25 19:41 UTC · original
Independent WARP/CPU verification
Head:
88d7c75f72e4020536d36d77b85bd65b36918c7cBase:
origin/main13f91caee25f2fdf2c062be5f7a27f058e51cbcaStatus: open, non-draft; clean merge tree; no
oni-swrcomment on this head.Environment: Windows x64, WARP selected (
VICTORY_WARP=1,VICTORY_D3D12_WARP=1),dxil.dll1.8.2502.11 from Windows SDK 10.0.26100.0; rustc 1.98.1.Commands (each with
CARGO_TARGET_DIR=D:\victory-warp-2690-targetand the WARP variables above):cargo test --locked -p victory-hlecargo test --locked -p victory-hle keyboard_reading_clears_previous_gamepad_state;cargo test --locked -p victory-hle key_state_terminates_a_reused_buffercargo clippy --locked -p victory-hle --all-targets -- -D warningsResults: baseline 148 passed, 0 failed (146 unit + 2 integration); PR 150 passed, 0 failed (148 unit + 2 integration). Targeted regressions 2/2 passed. Clippy passed.
Negative control: reverted both production handlers; each targeted regression failed (exit 101), as expected. No implementation bug found.
Not tested: physical GPU, retail title, release build. AI-assisted: Codex (gpt-6-luna).
@fuzeofficlal on GitHub · 2026-11-25 19:43 UTC · original
Independent Windows 11 verification and review of
88d7c75(on13f91ca, plus combined test with #2717 + #2718):Verification (
rustc 1.98.1MSVC)cargo xtask policy: 184 files ok.cargo clippy --locked -p victory-hle --all-targets -- -D warningsand--features diagnostics: 0 warnings.cargo test --locked -p victory-hle --lib modules::gameinput: 11 passed, 0 failed; fullvictory-hle --lib: 148 passed, 0 failed.git merge-tree;--features diagnosticsmodules::gameinput13 passed, fullvictory-hle --lib150 passed, 0 failed.Review Notes
count == 0guards run before any pointer arithmetic,out.add(n)stays strictly inside[0..count)whenn < count, and non-keyboard/non-gamepad readings clearout[0]/*outcleanly. (Minor optional note: clearingout[n..count]rather than only the single null terminatorout[n]would also clear stale tail entries if a caller scans past the terminator, though writing the terminator atout[n]already matches the documented GameInput contract.) Clean and ready to merge.@Marvisak on GitHub · 2026-11-25 23:18 UTC · original
Automated triage for the maintainers.
In
crates/victory-hle/src/modules/gameinput.rs,gamepad_statenow writes an at-restPadStateand returns false for a keyboard reading, andkey_statewrites one zeroedKeyStateafter the last key when the caller's array has room.key_statealso returns 0 early forcount == 0and for gamepad readings. The return values are unchanged, so callers that use the returned count behave the same. The PR cites the public reference pages for GetGamepadState and GetKeyState. I could not open them from here, so a maintainer may want to confirm the terminator wording. The writes stay inside[0, count)and both new tests cover reused buffers. CI (check) passes.This is a recommendation for a maintainer to look, not an approval.
Generated by Claude Code
@Dukestar69 on GitHub · 2026-11-26 05:11 UTC · original · approved these changes
Tested merged onto
origin/main(63bcca4) on Windows 11 x64:cargo test -p victory-hle --lib modules::gameinput::: 12 passed, 0 failed (including newkeyboard_reading_clears_previous_gamepad_stateandkey_state_terminates_a_reused_buffer).cargo clippy -p victory-hle --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@futurepro62 on GitHub · 2026-11-26 12:24 UTC · original
NVIDIA full-suite run, to go with the reports above by Dukestar69, fuzeofficlal, oni-swr, since none of them names a GPU run. Tested exact head
88d7c75(on its base13f91ca).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 775 passed, 0 failed, 9 ignored.keyboard_reading_clears_previous_gamepad_state,key_state_terminates_a_reused_buffer.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#2571), so without the skip the rest of that crate never reports;dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
@fuzeofficlal on GitHub · 2026-11-26 13:24 UTC · original · reviewed
The
gamepad_statechange (crates/victory-hle/src/modules/gameinput.rs:1068-1079) matches the documented at-rest output for a reading without the gamepad kind. Forkey_state(gameinput.rs:1051-1067), writingKeyState::default()atout[n]satisfies callers that consume eitherout[..returned]or stop at the first zeroed{scanCode: 0, virtualKey: 0}terminator, while the GDK keyboard guide leaves spare tail entries unspecified.A few polish suggestions:
out[n]is cleared (as opposed to zeroing all ofout[n..count]), in case a caller scans the fullcountskipping zero entries.key_state_terminates_a_reused_bufferuses a 2-slot buffer with 1 key, leaving only 1 spare slot so it doesn't distinguish single-slot termination from full-tail clearing; extending it to >= 3 prefilled slots (plus zero-key, truncatedkeys.len() > count,count == 0, and nulloutcases) would lock down the exact contract.rustfmt --edition 2024 --checkflags line1598in the new testkeyboard_reading_clears_previous_gamepad_state(alongside 4 pre-existing lines ingameinput.rs).Local verification on commit
88d7c75f72e4:xtask policy(184 files ok),cargo clippy -p victory-hle --all-targets(defaultand--all-features),gameinput::tests (11 passed), and the fullvictory-hlesuite (148 unit + 2 integration = 150 passed, 0 failed) all pass.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.