Has anyone experienced issues with hot swapping xbox 360 controller's for the PC.
When assigning them, not only do they seem to assign in the wrong order (from the lights on the controllers) 1 becomes 2 and vice versa. But when I remove the second and reconnect it, it is moving up one space and becoming 3 and then 4 in succession.
I am removing them when SDL_JOYDEVICEREMOVED or SDL_JOYDEVICEADDED and reassigning them with the following code
#define MAX_JOYSTICKS 4
SDL_Joystick *ARRAY_of_joysticks[MAX_JOYSTICKS];
//the rest is encapsulated in a class
void FUNC_refresh_gamepads()
{
int INT_joystick_iter= 0;
for (int i= 0; i < SDL_NumJoysticks(); ++i)
{
SDL_Joystick *TEMP_joystick= nullptr;
TEMP_joystick= SDL_JoystickOpen(i);
if(TEMP_joystick)
{
printf("Name: %s\n", SDL_JoystickNameForIndex(i));
printf("Number of Axes: %d\n", SDL_JoystickNumAxes(TEMP_joystick));
printf("Number of Buttons: %d\n", SDL_JoystickNumButtons(TEMP_joystick));
printf("Number of Balls: %d\n", SDL_JoystickNumBalls(TEMP_joystick));
} else {
printf("Couldn't open Joystick %i\n", i);
}
if(SDL_JoystickGetAttached(TEMP_joystick))
{
ARRAY_of_joysticks[INT_joystick_iter]= TEMP_joystick;
INT_joystick_iter++;
}
}
}
void FUNC_remove_controllers()
{
for (int i= 0; i < MAX_JOYSTICKS; ++i)
{
if(ARRAY_of_joysticks[i])
{
SDL_JoystickClose(ARRAY_of_joysticks[i]);
}
}
}