We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5097

Summary: Emscripten: connecting and disconnecting real-joysticks can close virtual joysticks
Product: SDL Reporter: David Ludwig <dll>
Component: joystickAssignee: Sam Lantinga <slouken>
Status: NEW --- QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: dll
Version: HG 2.0   
Hardware: Other   
OS: Other   
Attachments: Fix #1: use SDL_GetNextJoystickInstanceID() for alloc'ing joystick-ids in Emscripten joystick backend

Description David Ludwig 2020-04-18 15:52:40 UTC
SDL2's Emscripten joystick backend appears to be allocating SDL_JoystickIDs using its own, private, integer counter, rather than through SDL_GetNextJoystickInstanceID().  This can have harmful effects if and when a virtual joystick is attached (using functionality new to SDL 2.0.13+).  For example, when connecting and disconnecting real game-controller hardware, Emscripten's joystick backend can assign an SDL_Joystick a SDL_JoystickID that is being used by an active virtual-joystick (which uses a different, joystick-subsystem backend).
Comment 1 David Ludwig 2020-04-18 16:13:38 UTC
Created attachment 4310 [details]
Fix #1: use SDL_GetNextJoystickInstanceID() for alloc'ing joystick-ids in Emscripten joystick backend

Here is an attempt at a fix.  It seems to work fine for me, however it could, perhaps, use more testing, and maybe review by someone more familiar with SDL2's Emscripten joystick backend.