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 - Emscripten: connecting and disconnecting real-joysticks can close virtual joysticks
Summary: Emscripten: connecting and disconnecting real-joysticks can close virtual joy...
Status: NEW
Alias: None
Product: SDL
Classification: Unclassified
Component: joystick (show other bugs)
Version: HG 2.0
Hardware: Other Other
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-04-18 15:52 UTC by David Ludwig
Modified: 2020-04-18 16:13 UTC (History)
1 user (show)

See Also:


Attachments
Fix #1: use SDL_GetNextJoystickInstanceID() for alloc'ing joystick-ids in Emscripten joystick backend (2.55 KB, patch)
2020-04-18 16:13 UTC, David Ludwig
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.