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

From 6d7c211fafd5404e6d10a143ab4c443ed9e61b5a Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Fri, 6 Sep 2024 10:15:16 -0700
Subject: [PATCH] Fixed race condition at startup that could cause a crash in
 the XInput driver

---
 src/joystick/windows/SDL_xinputjoystick.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/joystick/windows/SDL_xinputjoystick.c b/src/joystick/windows/SDL_xinputjoystick.c
index 490edf45e530f..7486a135ec9ac 100644
--- a/src/joystick/windows/SDL_xinputjoystick.c
+++ b/src/joystick/windows/SDL_xinputjoystick.c
@@ -46,11 +46,13 @@ bool SDL_XINPUT_Enabled(void)
 
 bool SDL_XINPUT_JoystickInit(void)
 {
-    s_bXInputEnabled = SDL_GetHintBoolean(SDL_HINT_XINPUT_ENABLED, true);
+    bool enabled = SDL_GetHintBoolean(SDL_HINT_XINPUT_ENABLED, true);
 
-    if (s_bXInputEnabled && !WIN_LoadXInputDLL()) {
-        s_bXInputEnabled = false; // oh well.
+    if (enabled && !WIN_LoadXInputDLL()) {
+        enabled = false; // oh well.
     }
+    s_bXInputEnabled = enabled;
+
     return true;
 }
 
@@ -218,7 +220,7 @@ void SDL_XINPUT_JoystickDetect(JoyStick_DeviceData **pContext)
 {
     int iuserid;
 
-    if (!s_bXInputEnabled || !XINPUTGETCAPABILITIES) {
+    if (!s_bXInputEnabled) {
         return;
     }