gameinput: force-feedback kind changes, SetParams features, locked motor reads, no null memcpy (RT-GAMEINPUT-FFB-HAPTIC-NULL) #2497

Merged
leonida/mandy
Tyrannys merged 2 commits from rt-gameinput-ffb-haptic-null into main 2026-11-29 01:03:07 +00:00

Pull request successfully merged and closed

Tyrannys commented 2026-11-27 19:37:41 +00:00

Claimed in the coordination issue as: RT-GAMEINPUT-FFB-HAPTIC-NULL (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7226661366). This is item 2 of @kevincommits' finding (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7226429207). Thanks for the careful review; the fake SDL in the test now refuses a type change, which is how the second bug hid.

Depends on: none. Branched from main, not from #2487 (which also touches gameinput.cpp, in clip_cursor). The two do not overlap.

What and why

runtime/shims/gameinput.cpp:

  1. ForceFeedbackEffect::SetParams checks the motor's features. It accepted any valid kind, including one the motor does not report, which CreateForceFeedbackEffect refuses. It now refuses such a kind too and leaves the effect unchanged. While the pad is unplugged (no features known), the parameters are taken as before.
  2. A kind change makes a new SDL effect. sync() sent a changed kind to SDL as update_effect on the existing effect. SDL_UpdateHapticEffect refuses a type change ("Updating effect type is illegal"), so the effect stopped and reported an error. The test did not see it because its fake update accepted anything. The poll thread now remembers the type it created the effect with. When the type changes, it stops and destroys the old effect and creates one of the new type. A change that keeps the type is still an update.
  3. Locked reads. CreateForceFeedbackEffect and IsForceFeedbackMotorPoweredOn read info.forceFeedbackMotorCount, ff_features and haptic without g().mu. The poll thread writes those in open_pad/close_pad while holding that lock. Both now take the lock, as SetForceFeedbackMotorGain and SetHapticMotorState already do.
  4. No memcpy to null. GetControllerAxisState/GetControllerButtonState with a null buffer called memcpy(nullptr, ..., 0), which is undefined behaviour. They now copy only when n is non-zero, as RawReport::GetRawData does.

Not changed: the zero-duration trigger haptic. With playCount >= 1 and duration == 0, SetHapticMotorState holds the level until the state is set again. That is deliberate in this shim:

  • gameinput_test asserts it ("no deadline at playCount 1 either: the level holds until it is set again").
  • It follows the rule gameinput_abi.h gives for force-feedback envelopes, where a duration of 0 lasts until stopped.

I have no source for GameInput's own behaviour here, so I left it as is rather than guess. If someone can confirm what the real runtime does (silence, or hold), it is a small follow-up.

Tested

gameinput_test (SDL3 virtual pads, fake haptics; no controller, no game data):

  • New:
    • CreateForceFeedbackEffect and SetParams refuse a kind the motor lacks. The fake wheel now reports every kind but inertia.
    • A refused SetParams changes nothing.
    • Changing constant to sine destroys one SDL effect and creates one, and the effect runs with no error. The fake update now refuses a type change, as SDL does.
    • The axis and button getters with a null buffer return 0.
  • On main (43a9d562d, only gameinput.cpp reverted), 9 checks fail. Among them are SetParams refuses a kind the motor does not report and a new kind replaces the SDL effect instead of updating its type. The later sine, spring and mute checks fail too, because the effect never runs again after the refused update. With the change, all pass.
  • ctest -R gameinput (SDL3 build): gameinput, gameinput_script, gameinput_host pass.

The lock change has no dedicated race test. The existing RT-262 stress (20,000 effects created and released while the poll thread runs) still passes.

No game files.

GPUs tested: profile M: NVIDIA GeForce RTX 4070 SUPER, 12 GB, desktop, driver 621.01, Windows 11 (CPU-only change; tests need no GPU)

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a)

🤖 Generated with Claude Code

Claimed in the coordination issue as: RT-GAMEINPUT-FFB-HAPTIC-NULL (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7226661366). This is item 2 of @kevincommits' finding (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7226429207). Thanks for the careful review; the fake SDL in the test now refuses a type change, which is how the second bug hid. Depends on: none. Branched from `main`, not from #2487 (which also touches `gameinput.cpp`, in `clip_cursor`). The two do not overlap. ### What and why `runtime/shims/gameinput.cpp`: 1. **`ForceFeedbackEffect::SetParams` checks the motor's features.** It accepted any valid kind, including one the motor does not report, which `CreateForceFeedbackEffect` refuses. It now refuses such a kind too and leaves the effect unchanged. While the pad is unplugged (no features known), the parameters are taken as before. 2. **A kind change makes a new SDL effect.** `sync()` sent a changed kind to SDL as `update_effect` on the existing effect. `SDL_UpdateHapticEffect` refuses a type change ("Updating effect type is illegal"), so the effect stopped and reported an error. The test did not see it because its fake `update` accepted anything. The poll thread now remembers the type it created the effect with. When the type changes, it stops and destroys the old effect and creates one of the new type. A change that keeps the type is still an update. 3. **Locked reads.** `CreateForceFeedbackEffect` and `IsForceFeedbackMotorPoweredOn` read `info.forceFeedbackMotorCount`, `ff_features` and `haptic` without `g().mu`. The poll thread writes those in `open_pad`/`close_pad` while holding that lock. Both now take the lock, as `SetForceFeedbackMotorGain` and `SetHapticMotorState` already do. 4. **No `memcpy` to null.** `GetControllerAxisState`/`GetControllerButtonState` with a null buffer called `memcpy(nullptr, ..., 0)`, which is undefined behaviour. They now copy only when `n` is non-zero, as `RawReport::GetRawData` does. **Not changed: the zero-duration trigger haptic.** With `playCount >= 1` and `duration == 0`, `SetHapticMotorState` holds the level until the state is set again. That is deliberate in this shim: - `gameinput_test` asserts it ("no deadline at playCount 1 either: the level holds until it is set again"). - It follows the rule `gameinput_abi.h` gives for force-feedback envelopes, where a duration of 0 lasts until stopped. I have no source for GameInput's own behaviour here, so I left it as is rather than guess. If someone can confirm what the real runtime does (silence, or hold), it is a small follow-up. ### Tested `gameinput_test` (SDL3 virtual pads, fake haptics; no controller, no game data): - New: - `CreateForceFeedbackEffect` and `SetParams` refuse a kind the motor lacks. The fake wheel now reports every kind but inertia. - A refused `SetParams` changes nothing. - Changing constant to sine destroys one SDL effect and creates one, and the effect runs with no error. The fake `update` now refuses a type change, as SDL does. - The axis and button getters with a null buffer return 0. - On `main` (`43a9d562d`, only `gameinput.cpp` reverted), 9 checks fail. Among them are `SetParams refuses a kind the motor does not report` and `a new kind replaces the SDL effect instead of updating its type`. The later sine, spring and mute checks fail too, because the effect never runs again after the refused update. With the change, all pass. - `ctest -R gameinput` (SDL3 build): `gameinput`, `gameinput_script`, `gameinput_host` pass. The lock change has no dedicated race test. The existing RT-262 stress (20,000 effects created and released while the poll thread runs) still passes. No game files. GPUs tested: profile M: NVIDIA GeForce RTX 4070 SUPER, 12 GB, desktop, driver 621.01, Windows 11 (CPU-only change; tests need no GPU) AI-assisted: yes (Claude Code) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
timbot103 commented 2026-11-28 02:01:42 +00:00

Reviewed at head aeb24285b (static review + verified gta6rt compiles cleanly on Windows 11 MSVC 2022 19.44; SDL3 is not installed in this local environment so gameinput_test was not executed).

Finding (Request changes)

  • ForceFeedbackEffect::SetParams allows changing GameInputForceFeedbackEffectKind (gameinput.cpp:2276-2285, 2360-2390; gameinput_test.cpp:1474-1491):
    Per the GameInput v0 IGameInputForceFeedbackEffect::SetParams contract, SetParams only permits updating parameters within the effect's original GameInputForceFeedbackEffectKind (changing kind must return false). At gameinput.cpp:2281, the check validates device_->ff_features & kind_feature(params->kind) instead of requiring params->kind == params_.kind, so a motor supporting both constant and sine allows mutating a constant effect into a sine effect (and gameinput_test.cpp:1474-1491 currently asserts that cross-kind change succeeds). Rejecting params->kind != params_.kind (leaving params_ untouched) and testing sine via a separate CreateForceFeedbackEffect call matches the GameInput v0 contract.

The mutex coverage on motor validation/powered-on reads (gameinput.cpp:1406-1418, 1488-1508, 2158-2177) and zero-length memcpy guards (270-282) look solid.

AI-assisted review.

Reviewed at head `aeb24285b` (static review + verified `gta6rt` compiles cleanly on Windows 11 MSVC 2022 `19.44`; SDL3 is not installed in this local environment so `gameinput_test` was not executed). ### Finding (Request changes) - **`ForceFeedbackEffect::SetParams` allows changing `GameInputForceFeedbackEffectKind` (`gameinput.cpp:2276-2285`, `2360-2390`; `gameinput_test.cpp:1474-1491`):** Per the GameInput v0 `IGameInputForceFeedbackEffect::SetParams` contract, `SetParams` only permits updating parameters within the effect's original `GameInputForceFeedbackEffectKind` (changing kind must return `false`). At `gameinput.cpp:2281`, the check validates `device_->ff_features & kind_feature(params->kind)` instead of requiring `params->kind == params_.kind`, so a motor supporting both constant and sine allows mutating a constant effect into a sine effect (and `gameinput_test.cpp:1474-1491` currently asserts that cross-kind change succeeds). Rejecting `params->kind != params_.kind` (leaving `params_` untouched) and testing sine via a separate `CreateForceFeedbackEffect` call matches the GameInput v0 contract. The mutex coverage on motor validation/powered-on reads (`gameinput.cpp:1406-1418`, `1488-1508`, `2158-2177`) and zero-length `memcpy` guards (`270-282`) look solid. AI-assisted review.
Tyrannys commented 2026-11-28 02:11:48 +00:00

Thanks @timbot103, fixed in 4a7084506.

  • ForceFeedbackEffect::SetParams now refuses any params->kind other than the effect's own. It returns false and leaves params_ untouched. The motor-feature check is no longer needed there: the motor reported the kind when the effect was created.
  • An effect's SDL type can now never change, so the destroy-and-recreate path this PR had added to sync() is unreachable. I removed it again; the SDL effect is only ever updated.
  • gameinput_test: SetParams refuses both a kind the motor lacks (inertia) and one it reports (sine). The parameters and the SDL effect stay unchanged (no create, no destroy). The sine-wave and spring checks now run on effects of their own, made with CreateForceFeedbackEffect.

Run here with SDL3 (build-gi, SDL3 from source):

  • gameinput_test: 371 checks, 0 failures.
  • ctest -R gameinput: gameinput, gameinput_script and gameinput_host pass, 3/3.
  • With the previous head's SetParams, the four new checks fail.

AI-assisted (Claude Code).

Thanks @timbot103, fixed in 4a7084506. - `ForceFeedbackEffect::SetParams` now refuses any `params->kind` other than the effect's own. It returns `false` and leaves `params_` untouched. The motor-feature check is no longer needed there: the motor reported the kind when the effect was created. - An effect's SDL type can now never change, so the destroy-and-recreate path this PR had added to `sync()` is unreachable. I removed it again; the SDL effect is only ever updated. - `gameinput_test`: `SetParams` refuses both a kind the motor lacks (inertia) and one it reports (sine). The parameters and the SDL effect stay unchanged (no create, no destroy). The sine-wave and spring checks now run on effects of their own, made with `CreateForceFeedbackEffect`. Run here with SDL3 (`build-gi`, SDL3 from source): - `gameinput_test`: 371 checks, 0 failures. - `ctest -R gameinput`: `gameinput`, `gameinput_script` and `gameinput_host` pass, 3/3. - With the previous head's `SetParams`, the four new checks fail. AI-assisted (Claude Code).
timbot103 reviewed 2026-11-28 14:36:46 +00:00
timbot103 left a comment
No description provided.
Static code audit of `4a7084506` against `ec740bcc3`. The same-kind check matches the GameInput v0 contract, the motor reads use the same lock as open and close, and both getters guard the copy. - `runtime/shims/gameinput.cpp:2175` now reaches the dynamically initialized local static in `g()` (`runtime/shims/gameinput.cpp:863`) from the powered-on query. The validation lock at `runtime/shims/gameinput.cpp:2164` also reaches it on rejected requests. Please keep the locking and initialize the shared state without a function-local static TLS guard. - `runtime/test/gameinput_test.cpp:1308` records one type for the whole fake device, and `runtime/test/gameinput_test.cpp:1311` ignores effect identity. The test creates a sine while a constant is alive, so the fake would reject a valid constant update at that point. Please track the type per live effect ID and check an update while both effects exist. The null-buffer assertion checks the return value. The existing stress case keeps capabilities stable until the poller joins. I reviewed both fixes in source. AI-assisted.
OreoFR commented 2026-11-28 22:03:08 +00:00

Verified by OreoFR

Run 1 (nat01)

  • Base: main c1ecf04ed + PR head 4a7084506; green run in a merge package of 11 PRs, no new ctest failure vs main
  • Test: ctest -R "^(gameinput|gameinput_script)$"
  • Red on main: gameinput 3 failures of 374 (SetParams force feedback return)
  • Green with the PR: 2/2 OK
  • Verdict: READY

Run 2 (lot 4)

  • Base: main 09c153948 + PR head 4a7084506; integration package 4 of 6 (2 PRs, merged without conflict)
  • Test: full runtime build; ctest -j 6 without the 28 tests that launch gta6rt; the PRs' Python tests
  • Red on main: n/a (integration test; main baseline: xbox_present and d3d12_set_descriptor_heaps)
  • Green with the PR: ctest: only xbox_present and d3d12_set_descriptor_heaps fail, as on main; the gameinput tests pass
  • Verdict: CLEAN PACKAGE (no new failure vs main)

Run 3 (lot 4 bis)

  • Base: main 33db04a70 + PR head 4a7084506; integration package of 15 PRs
  • Test: full runtime build; ctest -j 6 without the 28 tests that launch gta6rt; the PRs' Python tests; translator suite
  • Red on main: n/a (integration test; main baseline: xbox_present, and flaky xmem)
  • Green with the PR: ctest: only xbox_present fails as on main (xs_proxy_mock failed once, flaky: passes on rerun and 5/5 direct runs); Python: same failures as main, the PRs' tests pass; translator: 507 files, 6405 tests, 0 failures
  • Verdict: CLEAN PACKAGE (no new failure vs main)

All runs

  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

AI-assisted (Claude Code, Claude Opus 5.5).

**Verified by OreoFR** **Run 1 (nat01)** - Base: main `c1ecf04ed` + PR head `4a7084506`; green run in a merge package of 11 PRs, no new ctest failure vs main - Test: `ctest -R "^(gameinput|gameinput_script)$"` - Red on main: gameinput 3 failures of 374 (SetParams force feedback return) - Green with the PR: 2/2 OK - Verdict: READY **Run 2 (lot 4)** - Base: main `09c153948` + PR head `4a7084506`; integration package 4 of 6 (2 PRs, merged without conflict) - Test: full runtime build; ctest -j 6 without the 28 tests that launch gta6rt; the PRs' Python tests - Red on main: n/a (integration test; main baseline: xbox_present and d3d12_set_descriptor_heaps) - Green with the PR: ctest: only xbox_present and d3d12_set_descriptor_heaps fail, as on main; the gameinput tests pass - Verdict: CLEAN PACKAGE (no new failure vs main) **Run 3 (lot 4 bis)** - Base: main `33db04a70` + PR head `4a7084506`; integration package of 15 PRs - Test: full runtime build; ctest -j 6 without the 28 tests that launch gta6rt; the PRs' Python tests; translator suite - Red on main: n/a (integration test; main baseline: xbox_present, and flaky xmem) - Green with the PR: ctest: only xbox_present fails as on main (xs_proxy_mock failed once, flaky: passes on rerun and 5/5 direct runs); Python: same failures as main, the PRs' tests pass; translator: 507 files, 6405 tests, 0 failures - Verdict: CLEAN PACKAGE (no new failure vs main) **All runs** - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
enlight3d commented 2026-11-29 00:46:10 +00:00

RUN (Windows 11, red/green)

Tested heads: PR head 4a7084506926240b5770481d8ad0aa5f1a846299 (base 43a9d562d, 2 commits); main at 1bc055e6c2dedaa0de23ec79d8c4007c1dff1fb3. git merge-tree --write-tree main pr-2497 merges cleanly.

Machine: Windows 11 Pro 10.0.26300, MSVC 14.44 (VS 2022 Build Tools), RelWithDebInfo, Ninja, 8 jobs. GPU NVIDIA GeForce RTX 3090 24 GB, driver 621.40 (not used by these tests). SDL3 3.4.20 static via -DSDL3_DIR=<install>/cmake.

Commands (only the test targets were built, not the whole runtime):

cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DSDL3_DIR=<SDL3 3.4.20 static>/cmake -DLEONIDA_REQUIRE_VULKAN=ON
cmake --build runtime/build --target gameinput_test gameinput_host_test gameinput_host -j 8
ctest --test-dir runtime/build -R "^(gameinput|gameinput_script|gameinput_host)$" --output-on-failure

GREEN (PR head): gameinput_test is built against SDL3 (the shim is built, not the "built without SDL3" disabled placeholder). gameinput, gameinput_script, gameinput_host: 3/3 passed.

RED (behavioural, not a missing header): PR head with only runtime/shims/gameinput.cpp put back to the base version (43a9d562d), tests kept; rebuilt gameinput_test and ran ctest -R "^(gameinput|gameinput_script)$": gameinput FAILED with "371 checks, 3 failures":

  • FAIL force feedback: SetParams refuses a kind the motor does not report
  • FAIL force feedback: SetParams refuses another kind the motor does report
  • FAIL force feedback: a refused SetParams changes nothing
    gameinput_script still passed.

Note: the PR description is out of date against its head. It says "9 checks fail" on main and describes a kind change creating a new SDL effect; the current head (4a7084506, pushed after the description) makes the kind fixed for the effect's life (SetParams with another kind returns false), so only 3 checks go red here. The locked reads and the null-buffer memcpy change have no dedicated test (the lock one is not testable by ctest; the null-buffer getters are not in the red set above).
Link check: merged into main 1bc055e6c, gta6rt.exe builds and links (RelWithDebInfo, MSVC 19.44); no new imports vs main.

RUN (Windows 11, red/green) Tested heads: PR head `4a7084506926240b5770481d8ad0aa5f1a846299` (base `43a9d562d`, 2 commits); `main` at `1bc055e6c2dedaa0de23ec79d8c4007c1dff1fb3`. `git merge-tree --write-tree main pr-2497` merges cleanly. Machine: Windows 11 Pro 10.0.26300, MSVC 14.44 (VS 2022 Build Tools), RelWithDebInfo, Ninja, 8 jobs. GPU NVIDIA GeForce RTX 3090 24 GB, driver 621.40 (not used by these tests). SDL3 3.4.20 static via `-DSDL3_DIR=<install>/cmake`. Commands (only the test targets were built, not the whole runtime): ``` cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DSDL3_DIR=<SDL3 3.4.20 static>/cmake -DLEONIDA_REQUIRE_VULKAN=ON cmake --build runtime/build --target gameinput_test gameinput_host_test gameinput_host -j 8 ctest --test-dir runtime/build -R "^(gameinput|gameinput_script|gameinput_host)$" --output-on-failure ``` GREEN (PR head): `gameinput_test` is built against SDL3 (the shim is built, not the "built without SDL3" disabled placeholder). `gameinput`, `gameinput_script`, `gameinput_host`: 3/3 passed. RED (behavioural, not a missing header): PR head with only `runtime/shims/gameinput.cpp` put back to the base version (`43a9d562d`), tests kept; rebuilt `gameinput_test` and ran `ctest -R "^(gameinput|gameinput_script)$"`: `gameinput` FAILED with "371 checks, 3 failures": - FAIL force feedback: SetParams refuses a kind the motor does not report - FAIL force feedback: SetParams refuses another kind the motor does report - FAIL force feedback: a refused SetParams changes nothing `gameinput_script` still passed. Note: the PR description is out of date against its head. It says "9 checks fail" on main and describes a kind change creating a new SDL effect; the current head (`4a7084506`, pushed after the description) makes the kind fixed for the effect's life (SetParams with another kind returns false), so only 3 checks go red here. The locked reads and the null-buffer memcpy change have no dedicated test (the lock one is not testable by ctest; the null-buffer getters are not in the red set above). Link check: merged into main 1bc055e6c, gta6rt.exe builds and links (RelWithDebInfo, MSVC 19.44); no new imports vs main.
MoonEyes commented 2026-11-29 01:03:10 +00:00

Merged after enlight3d (Thib)'s red/green run (RUN, RTX 3090, driver 621.40, Windows 11: green with this PR, red without it, and gta6rt.exe still links) and a re-check here: no conflict with main 0ff4dd1c8, same head as run, no-game-data green, and the only ctest failures in the Windows/macOS CI jobs are tests this diff does not touch (known on main or Vulkan: vk_xdxr_postbuild_readback vk_bindless_dimensions d3d12_compile_pool xbox_present ).

AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.

Merged after **enlight3d** (Thib)'s red/green run ([RUN](https://github.com/ProjectLeonida/mandy/pull/2497#issuecomment-7248337875), RTX 3090, driver 621.40, Windows 11: green with this PR, red without it, and `gta6rt.exe` still links) and a re-check here: no conflict with `main` 0ff4dd1c8, same head as run, `no-game-data` green, and the only ctest failures in the Windows/macOS CI jobs are tests this diff does not touch (known on `main` or Vulkan: vk_xdxr_postbuild_readback vk_bindless_dimensions d3d12_compile_pool xbox_present ). _AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes._
Sign in to join this conversation.
No description provided.