I am using SFML 2.5.1.I have two Xbox One Controllers connected to my PC. Obviously they will have two ids, 0 and 1.
When I disconnect the one with id 0 (the first one) bad magic happens.
First of all, I can see a weird sequence of JoystickDisconnected/JoystickConnected events.
The 0 controller gets disconnected, and a new 0 controller gets connected.
Secondly, once the 0 controller is disconnected, events for connected controller are reported with id 0 and 1.
I wrote a simple code for tracing Joystick events.
sf::Event event;
while (m_window.pollEvent(event))
{
switch (event.type)
{
case sf::Event::JoystickMoved:
{
Diagnostics::Trace::Write("Controller move: Id:[{0}]\n", event.joystickMove.joystickId);
}
break;
case sf::Event::JoystickDisconnected:
{
Diagnostics::Trace::Write("Controller disconnected: Id:[{0}]\n", event.joystickConnect.joystickId);
}
break;
case sf::Event::JoystickConnected:
{
Diagnostics::Trace::Write("Controller connected: Id:[{0}]\n", event.joystickConnect.joystickId);
}
break;
}
}
This is the output after disconnecting 0 controller and moving a thumbstick on other, still connected controller.
Controller disconnected: Id:[0]
Controller connected: Id:[0]
Controller move: Id:[0]
Controller move: Id:[0]
Controller move: Id:[0]
Controller move: Id:[0]
Controller move: Id:[1]
Controller move: Id:[1]
Controller move: Id:[1]
Controller move: Id:[1]
Controller move: Id:[0]
Controller move: Id:[0]
Controller move: Id:[1]
Controller move: Id:[1]
As you can see:
1. Controller 0 gets somehow connected
2. Events are reported for both controllers 0 and 1 even there is only one controller connected.
This seems to be a bug in SFML library.
I have found two topics about similar problems, but there is no explanation what is going on.
https://en.sfml-dev.org/forums/index.php?topic=27376.0https://en.sfml-dev.org/forums/index.php?topic=24764.0