Is this a bug, or have I misunderstood the ‘event.cdevice.which’ value
on CONTROLLERDEVICEREMOVED?
We should make this more clear at the API level for SDL 2.1, but “which”
means something different for each of those events:
Sint32 which; /**< The joystick device index for the ADDED
event, instance id for the REMOVED or REMAPPED event */
The idea is when it’s added, you can do
SDL_GameControllerOpen(which)…and several other things that operate on
unopened joystick indexes. This is a number that might get recycled if
we add a stick after one has been removed, to keep
SDL_NumJoysticks()-sized arrays reasonable).
On removal, though, this will be an instance id. This number is unique
and increments on each new joystick the system sees. You can get this
for a controller with:
myInstance =
SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(myController));
(maybe for 2.1, we’ll get rid of joystick indexes and use instance ids
for everything.)
–ryan.