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 4090 - SDL_JoystickID first assignment is in the wrong order
Summary: SDL_JoystickID first assignment is in the wrong order
Status: NEW
Alias: None
Product: SDL
Classification: Unclassified
Component: joystick (show other bugs)
Version: 2.0.7
Hardware: x86_64 Windows 10
: P2 minor
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-02-21 20:18 UTC by Pasculator
Modified: 2018-02-21 20:18 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pasculator 2018-02-21 20:18:01 UTC
I am using this code to detect controllers connected to my system.

int numJoysticksEnumerated = SDL_NumJoysticks();
std::cout << "Number of joysticks to check: " << numJoysticksEnumerated << std::endl;
for (int i = 0; i < numJoysticksEnumerated; ++i) {
    std::cout << "Checking joystick ID " << i << std::endl;
    if (SDL_IsGameController(i)) {
        SDL_GameController* gamePad = SDL_GameControllerOpen(i);
        if (gamePad) {
            std::cout << "Controller detected." << std::endl;
        } else {
            logSDLError(std::cout, "Controller detection failure.");
        }
    }
}

When I call

SDL_ControllerButtonEvent::which

afterwards, the lowest index is the one of the controller I connected most recently and the highest index is the one of the controller I connected first. This seems counter-intuitive since the Xbox-controller lights show the controller that was connected first as the first controller and so on. If I connect an additional controller after the first detection and run the detection again, the new controller will get a higher ID.

If for example I do this in order:

Controller 1 connected
Controller 2 connected
Controller 3 connected
Start game
Run controller detection
Controller 4 connected
Run controller detection

The result is:

Controller    SDL_JoystickID
1             2
2             1
3             0
4             3