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

From d53b22e8f057136b7121cc6c2b660b34ea8b43a8 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

(cherry picked from commit 6d7c211fafd5404e6d10a143ab4c443ed9e61b5a)
(cherry picked from commit 5aadfd4eafc12036c4f8da4b925016c619f465af)
---
 src/joystick/windows/SDL_xinputjoystick.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/joystick/windows/SDL_xinputjoystick.c b/src/joystick/windows/SDL_xinputjoystick.c
index ca6585312eb6c..59c60835335b9 100644
--- a/src/joystick/windows/SDL_xinputjoystick.c
+++ b/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;
 }