We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4898 - No rumble because of integer overflow in SDL_JoystickRumble
Summary: No rumble because of integer overflow in SDL_JoystickRumble
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: joystick (show other bugs)
Version: 2.0.10
Hardware: All All
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-12-14 14:25 UTC by Mathieu Eyraud
Modified: 2020-01-26 20:48 UTC (History)
0 users

See Also:


Attachments
switch and xinput patch (1.11 KB, patch)
2019-12-17 10:48 UTC, Mathieu Eyraud
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mathieu Eyraud 2019-12-14 14:25:52 UTC
On a Dualshock 4 controller using hidapi driver, calling SDL_JoystickRumble with a duration too long (SDL_HAPTIC_INFINITY for example) causes the rumble to stop immediately.

This happens because of integer overflow on line 301 of SDL_hidapi_ps4.c 
(https://hg.libsdl.org/SDL/file/99ecd178999f/src/joystick/hidapi/SDL_hidapi_ps4.c#l301), which sets expiration time in the past.
Comment 1 Mathieu Eyraud 2019-12-14 16:01:25 UTC
This actually affects all hidapi drivers and Xinput as they use the same logic.

On the Dualshock 4, the rumble motor does not even start.
However, on the Xbox One controller the rumble works, maybe because the motor starts spinning faster.
Comment 2 Sam Lantinga 2019-12-16 18:19:30 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/448528dc13da
Comment 3 Mathieu Eyraud 2019-12-17 10:48:17 UTC
Created attachment 4105 [details]
switch and xinput patch

Switch hidapi and xinput also need to check for overflow, attached a patch for them.
Comment 4 Sam Lantinga 2020-01-26 20:48:51 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/8d2d9a00fc02