From 9a8d5215c6f6ce426a94f70ef7cc0dc5c2bd187a Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 27 Mar 2019 08:17:05 -0700 Subject: [PATCH] Handle potentially calling SDL_JoystickUpdate() and SDL_JoystickQuit() at the same time. --- src/joystick/SDL_joystick.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index a5b3e63b48d51..430934c33d3f2 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -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) { @@ -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();