Skip to content

gameinput: a force-feedback sustainDuration of UINT64_MAX runs forever instead of wrapping to a few ms - #7511

Closed
AirKyzzZ wants to merge 3 commits into
ProjectLeonida:mainfrom
AirKyzzZ:fix/gameinput-sustain-forever
Closed

AirKyzzZ wants to merge 3 commits into
ProjectLeonida:mainfrom
AirKyzzZ:fix/gameinput-sustain-forever

Conversation

@AirKyzzZ

@AirKyzzZ AirKyzzZ commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: new RT item (claim)

@ItsNotRexed: an exe/recomp PR, as you asked.

What and why

Microsoft's GameInputForceFeedbackEnvelope reference says to use UINT64_MAX as sustainDuration for an effect meant to run forever. build_effect added the three durations and rounded with (total_us + 999) / 1000, which wraps: a forever sustain alone became a 1 ms SDL effect, and with a 50 ms attack a 50 ms one, which the poll thread then also expired and reported as stopped.

A sustainDuration of UINT64_MAX is now an effect with no duration of its own, the same as an empty envelope: SDL's 60 s hold, re-run before it runs out. The attack still comes from the envelope.

Tested

Windows 10 22H2 (19045), RTX 2060 / NVIDIA 566.14, Ryzen 5 2600X, clang-cl 23.1.6 + lld-link with the VS 2022 14.44 STL, Windows SDK 10.0.26100, Ninja, SDL3 3.4.20 fetched, at 61fb48016:

  • gameinput_test (ctest): 345 checks, 0 failures.
  • The same test with main's gameinput.cpp (51e7c9dc8): 2 failures, the two new checks (SDL got a 50 ms length, and the effect had stopped after the 80 ms sleep).
  • 61fb48016 also keeps a forever effect's attack from replaying on the 20 s refresh: with only that fix reverted, 1 failure (the refresh re-runs it with its attack). Details in the comment below.

The 80 ms sleep only has to outlast the wrapped 50 ms on main; with the fix the effect is running whatever the sleep takes.

No game files. AI-assisted (Claude Code).

Checklist

  • 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. (no translator change)

…r instead of wrapping to a few ms

Signed-off-by: Maxime Mansiet <AirKyzzZ@users.noreply.github.com>
Signed-off-by: Maxime Mansiet <AirKyzzZ@users.noreply.github.com>

@devnull34 devnull34 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified: prevents 64-bit integer overflow when sustainDuration == UINT64_MAX in force-feedback envelope calculation, cleanly treating it as an endless/forever effect managed via kHapticHoldMs poll cycling.

…its attack again

Signed-off-by: Maxime Mansiet <AirKyzzZ@users.noreply.github.com>
@AirKyzzZ

Copy link
Copy Markdown
Contributor Author

Follow-up: the poll thread re-runs an endless effect every 20 s (kRumbleRefreshUs), and SDL_RunHapticEffect restarts the envelope, so a forever effect with an attack played its attack again every 20 s.

61fb48016: that refresh (same params, only the 20 s re-run) now builds the effect without its attack, so it restarts at its level. A new test seam, set_effect_refresh_us, lets gameinput_test drive the refresh without waiting 20 s.

I looked at giving SDL SDL_HAPTIC_INFINITY as the length so nothing needs re-running. SDL 3.4.20's header allows it for every type but ramp, and the Linux backend maps it to evdev's 0 (forever). The Windows DirectInput backend doesn't special-case it, though: dwDuration = length * 1000UL wraps in 32 bits to 4,294,966,296 us, about 71.6 min, not INFINITE, and Wine runs that same backend. The effect would still need a refresh, just less often, and ramp can't take it at all. Dropping the attack on the refresh works on every backend.

Tested 61fb48016 on RTX 2060 (NVIDIA 566.14), Windows 10 22H2, clang-cl 23.1.6, SDL3 3.4.20: gameinput_test 345 checks, 0 failures. With the fix reverted and the seam kept: 1 failure, FAIL force feedback: the refresh that keeps it going re-runs it at its level, without its attack. #7463 and #7815 still merge cleanly on top (git merge-tree), and the merged #7815 tree passes gameinput_test with 359 checks, 0 failures.

@Cryptoteep

Copy link
Copy Markdown
Contributor

Tested 61fb480 on Windows 11 x64, MSVC 19.44, Intel CC150: pass (gameinput_test.exe: 341 checks, 0 failures).

Built with CMake + Ninja via \scripts/build_runtime.ps1 -FetchSdl3\ (SDL 3.4.20).
Verified that \CreateForceFeedbackEffect\ with \sustainDuration == UINT64_MAX\ correctly starts as SDL 60s hold after attack, remains running post-attack, and periodic refresh via \set_effect_refresh_us\ re-runs at level without re-triggering the attack phase. Reverting the fix triggers the expected failure on refresh attack length.

@optinium51-bot

Copy link
Copy Markdown

Tested 61fb48016 merged onto main 867d922f0 (clean merge) on NVIDIA GeForce RTX 3060 (driver 616.92), Windows 11 26200, MSVC 14.52 (VS 2026), RelWithDebInfo + Ninja, with the GameInput shim built (-DLEONIDA_SDL3_FETCH=ON, SDL3 3.4.20): pass.

No game files. AI-assisted (Claude Code).

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.

5 participants