The code below lets me reproduce the problem I had using XBox 360 controllers. It would be good if somebody could try it with others. I am not sure whether it can be reproduced with only one controller, but it's probably worth a try as well.
Steps to reproduce:
- Connect one or more controllers and start the application, it should tell you how many controllers ("joysticks") it detected.
- Play around with the Joystick axes so the application receives joystick movement events. It should tell you how many it received per frame. The usual value using one controller and moving one axis should be like 3 per frame max.
- Exit the application, disconnect one or more controllers and repeat steps 1 and 2.
Now suddenly, while you are moving the joystick axis, the current frame should be locked until you stop moving, yielding many events received during a single frame and making the frame last for a long time ( = frame rate drop).
This keeps happening everytime you restart the application now until the system is restarted, so I guess it might be a driver issue related to the XBox 360 controller adapter.
This is the code in question:
#include <stdio.h>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
int main() {
//Create window
sf::RenderWindow window(sf::VideoMode(200, 150), "Joystick Test");
window.setFramerateLimit(60);
//Detect joysticks
printf("Detecting joysticks... ");
int numJoysticks = 0;
while(sf::Joystick::isConnected(numJoysticks))
numJoysticks++;
printf("%d joystick(s) detected!\n", numJoysticks);
//Blah
sf::Text text("See console output...");
text.setCharacterSize(16);
text.setPosition(sf::Vector2f(5, 5));
//Main loop
printf("Listening for joystick move events...");
sf::Clock clock;
sf::Event event;
while(window.isOpen()) {
int numJoystickMoved = 0;
while(window.pollEvent(event)) {
switch(event.type) {
case sf::Event::Closed:
window.close();
break;
case sf::Event::JoystickMoved:
numJoystickMoved++;
break;
default:
break;
}
}
if(numJoystickMoved)
printf("Received %d joystick movement events this frame!\n", numJoystickMoved);
float frameTime = clock.restart().asSeconds();
if(frameTime > 0.25f)
printf("This frame took %0.2f seconds!\n", frameTime);
window.clear();
window.draw(text);
window.display();
}
}