Skip to content

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
ProjectLeonida:mainfrom
Tyrannys:rt-gameinput-ffb-haptic-null
Open

Tyrannys wants to merge 1 commit into
ProjectLeonida:mainfrom
Tyrannys:rt-gameinput-ffb-haptic-null

Conversation

@Tyrannys

Copy link
Copy Markdown
Contributor

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

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

1 participant