gameinput: force-feedback kind changes, SetParams features, locked motor reads, no null memcpy (RT-GAMEINPUT-FFB-HAPTIC-NULL) #2497
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2497"
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?
Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-27T19:37:41Z.
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 touchesgameinput.cpp, inclip_cursor). The two do not overlap.What and why
runtime/shims/gameinput.cpp:ForceFeedbackEffect::SetParamschecks the motor's features. It accepted any valid kind, including one the motor does not report, whichCreateForceFeedbackEffectrefuses. 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.sync()sent a changed kind to SDL asupdate_effecton the existing effect.SDL_UpdateHapticEffectrefuses a type change ("Updating effect type is illegal"), so the effect stopped and reported an error. The test did not see it because its fakeupdateaccepted 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.CreateForceFeedbackEffectandIsForceFeedbackMotorPoweredOnreadinfo.forceFeedbackMotorCount,ff_featuresandhapticwithoutg().mu. The poll thread writes those inopen_pad/close_padwhile holding that lock. Both now take the lock, asSetForceFeedbackMotorGainandSetHapticMotorStatealready do.memcpyto null.GetControllerAxisState/GetControllerButtonStatewith a null buffer calledmemcpy(nullptr, ..., 0), which is undefined behaviour. They now copy only whennis non-zero, asRawReport::GetRawDatadoes.Not changed: the zero-duration trigger haptic. With
playCount >= 1andduration == 0,SetHapticMotorStateholds the level until the state is set again. That is deliberate in this shim:gameinput_testasserts it ("no deadline at playCount 1 either: the level holds until it is set again").gameinput_abi.hgives 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):CreateForceFeedbackEffectandSetParamsrefuse a kind the motor lacks. The fake wheel now reports every kind but inertia.SetParamschanges nothing.updatenow refuses a type change, as SDL does.main(43a9d562d, onlygameinput.cppreverted), 9 checks fail. Among them areSetParams refuses a kind the motor does not reportanda 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_hostpass.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
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a)🤖 Generated with Claude Code
Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-28T02:01:42Z.
Reviewed at head
aeb24285b(static review + verifiedgta6rtcompiles cleanly on Windows 11 MSVC 202219.44; SDL3 is not installed in this local environment sogameinput_testwas not executed).Finding (Request changes)
ForceFeedbackEffect::SetParamsallows changingGameInputForceFeedbackEffectKind(gameinput.cpp:2276-2285,2360-2390;gameinput_test.cpp:1474-1491):Per the GameInput v0
IGameInputForceFeedbackEffect::SetParamscontract,SetParamsonly permits updating parameters within the effect's originalGameInputForceFeedbackEffectKind(changing kind must returnfalse). Atgameinput.cpp:2281, the check validatesdevice_->ff_features & kind_feature(params->kind)instead of requiringparams->kind == params_.kind, so a motor supporting both constant and sine allows mutating a constant effect into a sine effect (andgameinput_test.cpp:1474-1491currently asserts that cross-kind change succeeds). Rejectingparams->kind != params_.kind(leavingparams_untouched) and testing sine via a separateCreateForceFeedbackEffectcall matches the GameInput v0 contract.The mutex coverage on motor validation/powered-on reads (
gameinput.cpp:1406-1418,1488-1508,2158-2177) and zero-lengthmemcpyguards (270-282) look solid.AI-assisted review.
Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-28T02:11:48Z.
Thanks @timbot103, fixed in
4a7084506.ForceFeedbackEffect::SetParamsnow refuses anyparams->kindother than the effect's own. It returnsfalseand leavesparams_untouched. The motor-feature check is no longer needed there: the motor reported the kind when the effect was created.sync()is unreachable. I removed it again; the SDL effect is only ever updated.gameinput_test:SetParamsrefuses 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 withCreateForceFeedbackEffect.Run here with SDL3 (
build-gi, SDL3 from source):gameinput_test: 371 checks, 0 failures.ctest -R gameinput:gameinput,gameinput_scriptandgameinput_hostpass, 3/3.SetParams, the four new checks fail.AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-28T14:36:46Z.
Review: COMMENTED
Static code audit of
4a7084506againstec740bcc3. 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:2175now reaches the dynamically initialized local static ing()(runtime/shims/gameinput.cpp:863) from the powered-on query. The validation lock atruntime/shims/gameinput.cpp:2164also 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:1308records one type for the whole fake device, andruntime/test/gameinput_test.cpp:1311ignores 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.
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T22:03:08Z.
Verified by OreoFR
Run 1 (nat01)
c1ecf04ed+ PR head4a7084506; green run in a merge package of 11 PRs, no new ctest failure vs mainctest -R "^(gameinput|gameinput_script)$"Run 2 (lot 4)
09c153948+ PR head4a7084506; integration package 4 of 6 (2 PRs, merged without conflict)Run 3 (lot 4 bis)
33db04a70+ PR head4a7084506; integration package of 15 PRsAll runs
AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-11-29T00:46:10Z.
RUN (Windows 11, red/green)
Tested heads: PR head
4a7084506926240b5770481d8ad0aa5f1a846299(base43a9d562d, 2 commits);mainat1bc055e6c2dedaa0de23ec79d8c4007c1dff1fb3.git merge-tree --write-tree main pr-2497merges 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):
GREEN (PR head):
gameinput_testis 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.cppput back to the base version (43a9d562d), tests kept; rebuiltgameinput_testand ranctest -R "^(gameinput|gameinput_script)$":gameinputFAILED with "371 checks, 3 failures":gameinput_scriptstill 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.Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T01:03:10Z.
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.exestill links) and a re-check here: no conflict withmain0ff4dd1c8, same head as run,no-game-datagreen, and the only ctest failures in the Windows/macOS CI jobs are tests this diff does not touch (known onmainor Vulkan: vk_xdxr_postbuild_readback vk_bindless_dimensions d3d12_compile_pool xbox_present ).AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.