Skip to content

Commit

Permalink
Fixed crash with joystick rumble after disconnection
Browse files Browse the repository at this point in the history
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 #10422
  • Loading branch information
slouken committed Jul 29, 2024
1 parent 67b973b commit 0a924b1
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/joystick/SDL_joystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -1733,7 +1733,14 @@ int SDL_RumbleJoystick(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint
retval = 0;
} else {
retval = joystick->driver->Rumble(joystick, low_frequency_rumble, high_frequency_rumble);
joystick->rumble_resend = SDL_GetTicks() + SDL_RUMBLE_RESEND_MS;
if (retval == 0) {
joystick->rumble_resend = SDL_GetTicks() + SDL_RUMBLE_RESEND_MS;
if (joystick->rumble_resend == 0) {
joystick->rumble_resend = 1;
}
} else {
joystick->rumble_resend = 0;
}
}

if (retval == 0) {
Expand Down Expand Up @@ -2408,12 +2415,14 @@ void SDL_UpdateJoysticks(void)
#endif /* SDL_JOYSTICK_HIDAPI */

for (joystick = SDL_joysticks; joystick; joystick = joystick->next) {
if (joystick->attached) {
joystick->driver->Update(joystick);
if (!joystick->attached) {
continue;
}

if (joystick->delayed_guide_button) {
SDL_GamepadHandleDelayedGuideButton(joystick);
}
joystick->driver->Update(joystick);

if (joystick->delayed_guide_button) {
SDL_GamepadHandleDelayedGuideButton(joystick);
}

now = SDL_GetTicks();
Expand Down

0 comments on commit 0a924b1

Please sign in to comment.