Skip to content

Clear stale button and key state in GameInput output buffers - #2715

Open
VlREX wants to merge 1 commit into
Marvisak:mainfrom
VlREX:fix/gameinput-stale-state
Open

VlREX wants to merge 1 commit into
Marvisak:mainfrom
VlREX:fix/gameinput-stale-state

Conversation

@VlREX

@VlREX VlREX commented Nov 25, 2026

Copy link
Copy Markdown

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

VlREX added a commit to VlREX/VIREX that referenced this pull request Nov 25, 2026
Cover small output buffers, retained readings, and stable sequence numbers.
The buffer and snapshot cases are adapted from MichaelSmithAI's
BastienRodz#2 regression based on Marvisak#927.
Place the test next to the keyboard reading tests so it can merge with Marvisak#2715.
@kotekompotek

Copy link
Copy Markdown

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

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown

Independent WARP/CPU verification

Head: 88d7c75f72e4020536d36d77b85bd65b36918c7c
Base: origin/main 13f91caee25f2fdf2c062be5f7a27f058e51cbca
Status: open, non-draft; clean merge tree; no oni-swr comment on this head.

Environment: Windows x64, WARP selected (VICTORY_WARP=1, VICTORY_D3D12_WARP=1), dxil.dll 1.8.2502.11 from Windows SDK 10.0.26100.0; rustc 1.98.1.

Commands (each with CARGO_TARGET_DIR=D:\victory-warp-2690-target and the WARP variables above):

  • Baseline and PR: cargo test --locked -p victory-hle
  • PR targeted: cargo test --locked -p victory-hle keyboard_reading_clears_previous_gamepad_state; cargo test --locked -p victory-hle key_state_terminates_a_reused_buffer
  • PR lint: cargo clippy --locked -p victory-hle --all-targets -- -D warnings

Results: 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

Copy link
Copy Markdown
Contributor

Independent Windows 11 verification and review of 88d7c75 (on 13f91ca, plus combined test with #2717 + #2718):

Verification (rustc 1.98.1 MSVC)

Review Notes

  • Null-pointer and count == 0 guards run before any pointer arithmetic, out.add(n) stays strictly inside [0..count) when n < count, and non-keyboard/non-gamepad readings clear out[0] / *out cleanly. (Minor optional note: clearing out[n..count] rather than only the single null terminator out[n] would also clear stale tail entries if a caller scans past the terminator, though writing the terminator at out[n] already matches the documented GameInput contract.) Clean and ready to merge.

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

In crates/victory-hle/src/modules/gameinput.rs, gamepad_state now writes an at-rest PadState and returns false for a keyboard reading, and key_state writes one zeroed KeyState after the last key when the caller's array has room. key_state also returns 0 early for count == 0 and 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 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested merged onto origin/main (63bcca4) on Windows 11 x64:

  • cargo test -p victory-hle --lib modules::gameinput::: 12 passed, 0 failed (including new keyboard_reading_clears_previous_gamepad_state and key_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).

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 26, 2026
@futurepro62

Copy link
Copy Markdown

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 base 13f91ca).

Tested

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gamepad_state change (crates/victory-hle/src/modules/gameinput.rs:1068-1079) matches the documented at-rest output for a reading without the gamepad kind. For key_state (gameinput.rs:1051-1067), writing KeyState::default() at out[n] satisfies callers that consume either out[..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:

  • Document in a short comment why only the single terminator slot out[n] is cleared (as opposed to zeroing all of out[n..count]), in case a caller scans the full count skipping zero entries.
  • key_state_terminates_a_reused_buffer uses 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, truncated keys.len() > count, count == 0, and null out cases) would lock down the exact contract.
  • rustfmt --edition 2024 --check flags line 1598 in the new test keyboard_reading_clears_previous_gamepad_state (alongside 4 pre-existing lines in gameinput.rs).

Local verification on commit 88d7c75f72e4: xtask policy (184 files ok), cargo clippy -p victory-hle --all-targets (default and --all-features), gameinput:: tests (11 passed), and the full victory-hle suite (148 unit + 2 integration = 150 passed, 0 failed) all pass.

BastienRodz added a commit to BastienRodz/VIctory that referenced this pull request Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants