Joystick questions


Could someone clarify whether I really need to check SDL_JoystickGetAttached() before calling SDL_JoystickClose()?

This is what the wiki docs imply here:\bCategoryJoystick\b)|(CategoryEnum)|(CategoryStruct)

However, looking through the SDL source code there seems to be no other way to deallocte the SDL_Joystick struct without calling SDL_JoystickClose, so wont closing only ‘attached’ joysticks cause leaks?

Also, is there any reason SDL_JoystickOpen can return 0 even if you’ve made sure device_index is in range [0,SDL_NumJoysticks()). This isn’t happening to me but is happening to a tester. Not a big deal I can just skip that joystick, but we’re having quite few problems with ‘allocating’ joysticks to users etc and anything could be useful!

What general strategy do people use to ‘assign’ joysticks to players? I was originally using a GUID based system, until I realized GUIDs are unique per device ‘type’ not per device ‘instance’!

I’m currently inserting/removing joysticks from a ‘mirror’ of the ‘device index’ array based onJOYDEVICEADDED and JOYDEVICEREMOVED events, but this is kind of clunky and doesn’t seem to be working 100% on all testers machines.

What I’d like to do is use JoystickInstanceID, but there’s no way to get that from device_index (there is an internal call for this though - would be very useful for it to be public!) so you need to first open each joystick when ‘allocating’ a joystick to determine it’s instanceID. I was hoping to avoid this.

Mark Sibly