Handle potentially calling SDL_JoystickUpdate() and SDL_JoystickQuit() at the same time.
authorSam Lantinga <slouken@libsdl.org>
Wed, 27 Mar 2019 08:17:05 -0700
changeset 12672d5b4d374a312
parent 12671 a7b99312d9f3
child 12673 95689b6959db
Handle potentially calling SDL_JoystickUpdate() and SDL_JoystickQuit() at the same time.
src/joystick/SDL_joystick.c
     1.1 --- a/src/joystick/SDL_joystick.c	Mon Mar 25 12:59:30 2019 -0400
     1.2 +++ b/src/joystick/SDL_joystick.c	Wed Mar 27 08:17:05 2019 -0700
     1.3 @@ -699,9 +699,12 @@
     1.4      int i;
     1.5  
     1.6      /* Make sure we're not getting called in the middle of updating joysticks */
     1.7 -    SDL_assert(!SDL_updating_joystick);
     1.8 -
     1.9      SDL_LockJoysticks();
    1.10 +    while (SDL_updating_joystick) {
    1.11 +        SDL_UnlockJoysticks();
    1.12 +        SDL_Delay(1);
    1.13 +        SDL_LockJoysticks();
    1.14 +    }
    1.15  
    1.16      /* Stop the event polling */
    1.17      while (SDL_joysticks) {
    1.18 @@ -724,8 +727,9 @@
    1.19                          SDL_JoystickAllowBackgroundEventsChanged, NULL);
    1.20  
    1.21      if (SDL_joystick_lock) {
    1.22 -        SDL_DestroyMutex(SDL_joystick_lock);
    1.23 +        SDL_mutex *mutex = SDL_joystick_lock;
    1.24          SDL_joystick_lock = NULL;
    1.25 +        SDL_DestroyMutex(mutex);
    1.26      }
    1.27  
    1.28      SDL_GameControllerQuitMappings();