Skip to content

Commit

Permalink
Handle potentially calling SDL_JoystickUpdate() and SDL_JoystickQuit(…
Browse files Browse the repository at this point in the history
…) at the same time.
  • Loading branch information
slouken committed Mar 27, 2019
1 parent 2bf165e commit a83266d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/joystick/SDL_joystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,9 +699,12 @@ SDL_JoystickQuit(void)
int i;

/* Make sure we're not getting called in the middle of updating joysticks */
SDL_assert(!SDL_updating_joystick);

SDL_LockJoysticks();
while (SDL_updating_joystick) {
SDL_UnlockJoysticks();
SDL_Delay(1);
SDL_LockJoysticks();
}

/* Stop the event polling */
while (SDL_joysticks) {
Expand All @@ -724,8 +727,9 @@ SDL_JoystickQuit(void)
SDL_JoystickAllowBackgroundEventsChanged, NULL);

if (SDL_joystick_lock) {
SDL_DestroyMutex(SDL_joystick_lock);
SDL_mutex *mutex = SDL_joystick_lock;
SDL_joystick_lock = NULL;
SDL_DestroyMutex(mutex);
}

SDL_GameControllerQuitMappings();
Expand Down

0 comments on commit a83266d

Please sign in to comment.