Browse Source

Lock joysticks while attaching a virtual one

Sam Lantinga 2 years ago
parent
commit
12413ab31f
1 changed files with 6 additions and 1 deletions
  1. 6 1
      src/joystick/SDL_joystick.c

+ 6 - 1
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