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 5070

Summary: Spurious removed+added events when one joystick is unplugged
Product: SDL Reporter: Anthony Heathcoat <zolcos>
Component: joystickAssignee: Sam Lantinga <slouken>
Status: NEW --- QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: HG 2.1   
Hardware: x86_64   
OS: Windows 10   

Description Anthony Heathcoat 2020-04-02 20:57:34 UTC
Using SDL revision 31702522ddbc
In short, when unplugging a joystick, SDL sends a correct remove event, but also sends a remove event followed by an added event for all the other joysticks on the system as well.

-- The setup:
I have 3 joystick devices connected: one actual flight stick, a throttle, and a steering wheel.
My program uses SDL_AddEventWatch to watch for add/remove events and act accordingly so it can continue to use a replugged joystick like nothing happened. I am using polling for button and axis state.

-- At runtime:
When unplugging just one joystick, I would expect to get just one removed event. Here's what happens instead:
- Nothing special happens for about 23 seconds, everything continues to work except the joystick that was unplugged.
- I get 3 separate SDL_JOYDEVICEREMOVED events, one for each joystick on the system.
- About 7 seconds pass where no joysticks work for polling state, not even the ones still connected.
- I get 2 SDL_JOYDEVICEADDED events, one for each of the joysticks that were never unplugged. My program picks this up, does the necessary work, and now the 2 that were never unplugged become pollable again. (However, opening haptics on the new instance of the wheel produces a haptic device that opens successfully but fails to run any events but this part may be my bug.)

As of now my program can't tell which of the 3 removed events are for joysticks that were really removed, because functions that query joystick layout and state continue to return valid values for all 3 devices.