Skip to content

GameInput: return the newest reading when controller timestamps tie - #4924

Open
Brandon-C-Wheeler wants to merge 1 commit into
ItsNotRexed:mainfrom
Brandon-C-Wheeler:fix/gameinput-reading-order
Open

Brandon-C-Wheeler wants to merge 1 commit into
ItsNotRexed:mainfrom
Brandon-C-Wheeler:fix/gameinput-reading-order

Conversation

@Brandon-C-Wheeler

Copy link
Copy Markdown

Claimed in the coordination issue. Related to #660.

What and why

If a controller connects in the same poll that another controller registers a button press, GetCurrentReading can return the newly connected controller’s idle state. The shim records that state first and the button press second, but gives both the same timestamp. The unfiltered and aggregate-device lookups broke the tie by connection order.

Both lookups now use the order assigned when each reading enters history. A caller gets the same latest reading whether it asks for the current state or walks the stream with GetNextReading.

The input-kind filtering changes in #2413, #2612 and #2939 touch the same lookup code. If one lands first, keep its device filter and use Reading::order() to choose the newest matching reading.

Tested

  • Windows 11 x64, MSVC 19.44, Release. The regression uses two SDL virtual gamepads and exercises both lookup paths. No physical controller or GPU is involved.
  • With the regression on the original implementation, history recorded both inputs in order with equal timestamps. The two current-reading assertions failed. The other 330 checks passed.
  • With the fix, all 332 GameInput checks passed. Both gameinput and active_input passed five consecutive runs with ctest --test-dir runtime/build -C Release -R "^(gameinput|active_input)$" --repeat until-fail:5 --output-on-failure.

AI-assisted with Codex. The patch contains only shim code and a synthetic test.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 0250734 on Windows 11 with MSVC 14.51 and SDL 3.4.20. Both current-reading lookups return the final history entry when timestamps match.

I built gameinput_test and active_input_test in RelWithDebInfo. I ran ctest --test-dir build -C RelWithDebInfo -R "^(gameinput|active_input)$" --repeat until-fail:5 --output-on-failure. Both tests pass five consecutive runs.

I also attached two idle virtual pads in the same poll as a button press on the first pad. All three readings have the same timestamp. The unfiltered and aggregate lookups both return the button press at the end of the stream. This local three-pad variant passes all 332 checks.

With the original head test and the shim from merge base 3faac55, exactly two of 332 checks fail: the unfiltered lookup and the aggregate lookup each select the wrong reading. These tests use virtual controllers. No physical input device or GPU is required.

AI-assisted.

@tupacfan04

Copy link
Copy Markdown
Contributor

Good to merge. gameinput_test gives 332 checks / 0 failures, and ctest -R "^(gameinput|active_input)$" --repeat until-fail:3 passes 2/2. Negative control: the PR's test on main's shim fails hot-plug: unfiltered current... and ...aggregate current... (330/332). compileall clean, test_ctest_registration OK, merge clean.

The tie-break at runtime/shims/gameinput.cpp:2317,2327 reuses the existing order() rule from GetNextReading; the device-specific path at 2323 is correctly untouched. Nit: docs/gameinput.md:386 documents the order rule only for the stream; mention GetCurrentReading too.

Not run: full ctest sweep, MSAA typeless RTV, console/Xbox behaviour, AMD host.

Approve. AI-assisted review, no game files.

@memorypressure

Copy link
Copy Markdown

Verified against main 3faac55, which this branch already contains at its tip (clean fast-forward). The fix is internally consistent: Reading::order() is exactly the sequence GetNextReading/GetPreviousReading walk (gameinput.cpp:288, 2272-2277), so ties in the shared per-poll timestamp now resolve to the last-recorded reading instead of connected-list iteration order; the hot-plug test exercises precisely the tie case. The C++ build/test needs cmake/SDL virtual gamepads and was not possible on this CPU-only verifier — and GitHub reports no checks scheduled on the branch at all, so a CI trigger is needed before this can be judged on its legs. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants