Fixed crash with joystick rumble after disconnection

This prevents continuing a rumble after the first one fails, and fixes a long standing crash issue if rumble is started immediately before the controller is disconnected.

Thanks to @AntTheAlchemist for the key bug report that showed what was happening here.

Fixes https://github.com/libsdl-org/SDL/issues/10422

(cherry picked from commit 0a924b185d)
This commit is contained in:
Sam Lantinga
2024-07-29 12:48:40 -07:00
parent 15c73f5bfe
commit 7fdf794377
+9 -3
View File
@@ -1412,10 +1412,14 @@ int SDL_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint
retval = 0; retval = 0;
} else { } else {
retval = joystick->driver->Rumble(joystick, low_frequency_rumble, high_frequency_rumble); retval = joystick->driver->Rumble(joystick, low_frequency_rumble, high_frequency_rumble);
if (retval == 0) {
joystick->rumble_resend = SDL_GetTicks() + SDL_RUMBLE_RESEND_MS; joystick->rumble_resend = SDL_GetTicks() + SDL_RUMBLE_RESEND_MS;
if (!joystick->rumble_resend) { if (joystick->rumble_resend == 0) {
joystick->rumble_resend = 1; joystick->rumble_resend = 1;
} }
} else {
joystick->rumble_resend = 0;
}
} }
if (retval == 0) { if (retval == 0) {
@@ -2177,13 +2181,15 @@ void SDL_JoystickUpdate(void)
#endif /* SDL_JOYSTICK_HIDAPI */ #endif /* SDL_JOYSTICK_HIDAPI */
for (joystick = SDL_joysticks; joystick; joystick = joystick->next) { for (joystick = SDL_joysticks; joystick; joystick = joystick->next) {
if (joystick->attached) { if (!joystick->attached) {
continue;
}
joystick->driver->Update(joystick); joystick->driver->Update(joystick);
if (joystick->delayed_guide_button) { if (joystick->delayed_guide_button) {
SDL_GameControllerHandleDelayedGuideButton(joystick); SDL_GameControllerHandleDelayedGuideButton(joystick);
} }
}
now = SDL_GetTicks(); now = SDL_GetTicks();
if (joystick->rumble_expiration && if (joystick->rumble_expiration &&