Lock joysticks while attaching a virtual one
diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c
index 73c2466..c96bee0 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