Browse Source

Fixed race condition at startup that could cause a crash in the XInput driver

(cherry picked from commit 6d7c211fafd5404e6d10a143ab4c443ed9e61b5a)
Sam Lantinga 7 months ago
parent
commit
5aadfd4eaf
1 changed files with 5 additions and 3 deletions
  1. 5 3
      src/joystick/windows/SDL_xinputjoystick.c

+ 5 - 3
src/joystick/windows/SDL_xinputjoystick.c

@@ -65,11 +65,13 @@ SDL_bool SDL_XINPUT_Enabled(void)
 
 int SDL_XINPUT_JoystickInit(void)
 {
-    s_bXInputEnabled = SDL_GetHintBoolean(SDL_HINT_XINPUT_ENABLED, SDL_TRUE);
+    SDL_bool enabled = SDL_GetHintBoolean(SDL_HINT_XINPUT_ENABLED, SDL_TRUE);
 
-    if (s_bXInputEnabled && WIN_LoadXInputDLL() < 0) {
-        s_bXInputEnabled = SDL_FALSE; /* oh well. */
+    if (enabled && WIN_LoadXInputDLL() < 0) {
+        enabled = SDL_FALSE; /* oh well. */
     }
+    s_bXInputEnabled = enabled;
+
     return 0;
 }