From 12413ab31fce61d436ab9ce18d6a2b964e39d945 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 8 Sep 2022 13:33:04 -0700 Subject: [PATCH] Lock joysticks while attaching a virtual one --- src/joystick/SDL_joystick.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index 73c246632..c96bee009 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -604,7 +604,12 @@ int SDL_JoystickAttachVirtualEx(const SDL_VirtualJoystickDesc *desc) { #if SDL_JOYSTICK_VIRTUAL - return SDL_JoystickAttachVirtualInner(desc); + int result; + + SDL_LockJoysticks(); + result = SDL_JoystickAttachVirtualInner(desc); + SDL_UnlockJoysticks(); + return result; #else return SDL_SetError("SDL not built with virtual-joystick support"); #endif