Jump to content
  • Advertisement
Sign in to follow this  
Ubermeowmix

SDL2 xbox controller hotswapping issues!

This topic is 789 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]);
            }
        }
}

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!