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 4488 - SDL_PrivateJoystickAdded generates incorrect device_index
Summary: SDL_PrivateJoystickAdded generates incorrect device_index
Status: NEW
Alias: None
Product: SDL
Classification: Unclassified
Component: joystick (show other bugs)
Version: 2.0.9
Hardware: x86_64 Windows 10
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-02-04 16:33 UTC by Rutger Janssen
Modified: 2019-02-04 16:33 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rutger Janssen 2019-02-04 16:33:12 UTC
When performing the following reproduction steps, I noticed that the device index is incorrect reported with a PS4 and Xbox controller

1. Connect PS4 and XBox controller
2. Start application
SDL_PrivateJoystickAdded already creates device_index of 0 twice, but this is not a problem as no events are generated and devices are added later by looping over all devices.
3. Remove PS4 controller
4. Attach PS4 controller
Notice that instance_id is 2 and device index is 0.
5. Call SDL_GameControllerOpen with the device index (0)
Notice that the instance_id is 1 (The xbox controller)

I would expect that the device index that's reported in the event to be the same index I can use to open the controller.

Based on my short investigation, this has to do that the device index is based on the joystick driver order, windows_joystick first, HIDAPI_joystick later. However the device enumeration first detects the PS4 controller but as WINDOWS_JoystickDetect cleared the SYS_Joystick list, it doesn't know of the windows controllers and is given index 0. The XInput controller is then added and given index 0, as it's first in the driver list, thus changing the index of the PS4 controller.