Repository navigation
gameinput: force-feedback kind changes, SetParams features, locked motor reads, no null memcpy (RT-GAMEINPUT-FFB-HAPTIC-NULL) - #2497
Open
Tyrannys wants to merge 1 commit into
Conversation
…tor reads, no null memcpy From a review of the shim by kevincommits (ProjectLeonida#1608): - ForceFeedbackEffect::SetParams accepted any kind, also one the motor does not report, which CreateForceFeedbackEffect refuses. It now refuses it the same way. - A kind change through SetParams was sent to SDL as an update of the existing effect, which SDL_UpdateHapticEffect refuses ("Updating effect type is illegal"), so the effect stopped. The poll thread now destroys the old SDL effect and creates one of the new type. The test's fake haptics refuses a type change in an update, as SDL does. - CreateForceFeedbackEffect and IsForceFeedbackMotorPoweredOn read the motor count, features and haptic handle that open_pad and close_pad write on the poll thread under g().mu, without the lock. They take it now. - GetControllerAxisState and GetControllerButtonState called memcpy with a null buffer for 0 bytes. They copy only when there is something to copy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claimed in the coordination issue as: RT-GAMEINPUT-FFB-HAPTIC-NULL (#1608 (comment)). This is item 2 of @kevincommits' finding (#1608 (comment)). 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