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 5063

Summary: Removed joysticks should center their inputs
Product: SDL Reporter: Ryan C. Gordon <icculus>
Component: joystickAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 Keywords: target-2.0.14
Version: HG 2.0   
Hardware: x86_64   
OS: Linux   

Description Ryan C. Gordon 2020-03-26 20:49:42 UTC
In SDL_PrivateJoystickRemoved(), we should generate fake input events for any buttons that were still pressed down and center any axes before sending the SDL_JOYDEVICEREMOVED event.

This allows an app that doesn't handle hotplugging to at least not assume the player is pressing down the fire button forever if they yank out the USB cable suddenly.

--ryan.
Comment 1 Ryan C. Gordon 2020-03-26 20:50:21 UTC
Gonna assign this to myself in case this is quick to implement right now.

--ryan.
Comment 2 Ryan C. Gordon 2020-03-26 20:56:06 UTC
Oh, it turns out we already do this (grep for "force_recentering") but we send these recentering events _after_ SDL_JOYDEVICEREMOVED, which is a problem in the _opposite_ direction; if you handle hotplugging, you probably closed the joystick by the time these would show up.

Going to move the force_recentering code to a separate function, so the removal code can call it directly.

Also, force_recentering is only set in one other place (DARWIN_JoystickUpdate), and for the same reason: device removal. We should probably clean that out eventually too.

--ryan.
Comment 3 Ryan C. Gordon 2020-03-26 22:50:04 UTC
Fixed in https://hg.libsdl.org/SDL/rev/9adcb74f0be2

--ryan.