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 4886 - disconnecting and reconnecting game controller from/to system does not generate button/axis events
Summary: disconnecting and reconnecting game controller from/to system does not genera...
Status: NEW
Alias: None
Product: SDL
Classification: Unclassified
Component: joystick (show other bugs)
Version: 2.0.10
Hardware: x86_64 Linux
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords: target-2.0.16
Depends on:
Blocks:
 
Reported: 2019-12-06 07:36 UTC by Rafael Kitover
Modified: 2020-07-16 18:29 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rafael Kitover 2019-12-06 07:36:03 UTC
Disconnecting a game controller from the system generates an SDL_CONTROLLERDEVICEREMOVED event, and subsequently reattaching the controller generates an SDL_CONTROLLERDEVICEADDED event correctly.

However, even if the device is closed and reopened, there are no further events generated for e.g. button presses or axis motion for this controller in this scenario.

This is as opposed to connecting a controller with the application running, in that case the SDL_CONTROLLERDEVICEADDED event fires and subsequently button/axis events are also received.

The problem is present on both linux and windows with SDL 2.0.10.

I tested with an xbox 360 controller (wired and wireless.)

My apologies if I'm doing something wrong.
Comment 1 Rafael Kitover 2019-12-24 15:16:21 UTC
I solved this problem in our app by falling back to polling the controllers on an interval after calling SDL_PollEvent().

The ADDED/REMOVED events allow for having a valid device handle.
Comment 2 Ryan C. Gordon 2020-03-24 20:15:38 UTC
Just to be clear, did you work around a problem in SDL or was this fixing the app to use the API correctly?  It's a common mistake to confuse device indexes and instance IDs for controllers. Plugging the same controller again will give it a different instance_id (and definitely can't use the existing SDL_GameController pointer without reopening the device).

I'm trying to decide if we have a bug to fix in SDL or if this bug can just be closed as resolved.

--ryan.
Comment 3 Rafael Kitover 2020-03-25 00:00:09 UTC
This is my joystick handler:

https://github.com/visualboyadvance-m/visualboyadvance-m/blob/master/src/wx/widgets/wx/sdljoy.h

https://github.com/visualboyadvance-m/visualboyadvance-m/blob/master/src/wx/widgets/sdljoy.cpp

As far as I know I am following the API correctly.

I am closing the device and obtaining a new device pointer on a device added event. I've tried various variations of this, and it makes no difference.