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 4189

Summary: Joystick reports wrong `which` value on event and wrong `GUID` on SDL_JoystickGetDeviceGUID.
Product: SDL Reporter: jlalvarez
Component: joystickAssignee: Sam Lantinga <slouken>
Status: RESOLVED INVALID QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2    
Version: 2.0.8   
Hardware: x86_64   
OS: Windows 7   

Description jlalvarez 2018-06-07 13:42:03 UTC
On windows, with current (2.0.8) SDL version, if two joysticks are plugged SDL initially enumerates them as:

[SDL2] Joystick number 0 -- "Saitek X45"
  --> Buttons: 26
  -->    Axis: 6
  -->    Hats: 1
  -->   Balls: 0
  -->    GUID: "03000000a30600003c05000000000000"
[SDL2] Joystick number 1 -- "Generic   USB  Joystick  "
  --> Buttons: 12
  -->    Axis: 5
  -->    Hats: 1
  -->   Balls: 0
  -->    GUID: "03000000790000000600000000000000"

But immediately the events generated by Joystick 0 (Saitek X45) have the event `which` attribute set to 1, and the events generated by the joystick 0 (Generic) have the `which`attribute set to 1.

More worrying, if I disconnect joystick 1 (Generic) and whenever an event from Joystick 0 (Saitek) is received I call `SDL_JoystickGetDeviceGUID` with the events' `which` value, it will still be 1 and the returned GUID will be all-zero.

How to reproduce:
- Enumerate and open all joystick devices (SDL_JoystickOpen).
- register an event callback (SDL_AddEventWatch).
- Whenever a joystick event is received, call SDL_JoystickGetDeviceGUID with `which`as an argument.

At this point, printing the event `which`argument should be swapped around between joystick 1 and 0. The device enumerated as '0' will have '1' on the `which` attribute and the other way around.

- Disconnect device 1
- Move device 0
- the returned GUID will be all-zero and the event `which` value should still be swapped. Somehow I am receiving events from a device that does not exist/have GUID.
Comment 1 jlalvarez 2018-06-07 14:56:54 UTC
Missread the meaning of `which` on the docs. This bug ain't a bug but my own error.