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 1701 - DirectX back-end handles multiple joysticks incorrectly.
Summary: DirectX back-end handles multiple joysticks incorrectly.
Status: RESOLVED INVALID
Alias: None
Product: SDL
Classification: Unclassified
Component: joystick (show other bugs)
Version: HG 2.0
Hardware: All Windows (All)
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-01-21 19:54 UTC by Erik Soma
Modified: 2013-01-22 14:37 UTC (History)
1 user (show)

See Also:


Attachments
Fix for bug (10.19 KB, patch)
2013-01-21 19:54 UTC, Erik Soma
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Erik Soma 2013-01-21 19:54:06 UTC
Created attachment 1025 [details]
Fix for bug

When multiple joysticks are attached to the system the joysticks are opened incorrectly. Specifically, the SDL_Joystick will be assigned the wrong instance_id for the joystick_id requested. This is contrary to what the user expects, since the instance_id is used for for event.[type].which in joystick events.

With two joysticks attached to the system: If we SDL_OpenJoystick(0) we will get an SDL_Joystick with the instance_id 1. If we SDL_OpenJoystick(1) we will get an SDL_Joystick with the instance_id 0.

I determined that the implementation is handing out the internal directx joysticks in reverse order because of how the linked list of joysticks is being populated. Explains why it works fine with a single joystick.

I believe I've fixed the issue by using a linked list more similar to the one in the Linux joystick back-end (with a head/tail) and rewriting the callback function that enumerates the connected joysticks.

I need to do some more testing, especially regarding disconnecting and reconnecting devices, but I've attached a patch in the meantime for any potential feedback.
Comment 1 Erik Soma 2013-01-22 14:37:46 UTC
Upon further inspection it is fine I just didn't realize the separation between the joystick's instance id and device index was intentional. In hindsight it seems obvious :)