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

Summary: No rumble because of integer overflow in SDL_JoystickRumble
Product: SDL Reporter: Mathieu Eyraud <meyraud705>
Component: joystickAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: 2.0.10   
Hardware: All   
OS: All   
Attachments: switch and xinput patch

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