From 5aadfd4eafc12036c4f8da4b925016c619f465af Mon Sep 17 00:00:00 2001 From: Sam Lantinga 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) --- 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 ca6585312e..59c6083533 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; }