SFML community forums

Help => Window => Topic started by: SamHenry97 on May 15, 2016, 11:36:46 pm

Title: Window pollEvents() causing lag when joystick not plugged in.
Post by: SamHenry97 on May 15, 2016, 11:36:46 pm
I'm having trouble with the event loop, "while(window.pollEvent(event))". When I don't have a joystick plugged in, it lags, and when I plug a joystick in, it starts running smoothly, even when I take it out again. I know this is because of how in the event loop, it is checking to see if the joystick is connected. I saw another thread that said to fix this, you need to get into the CPP file to edit some code. In other words, get into the SFML source code. I am not sure how to do this. If I could figure this out, I could fix the problem. Any ideas? Thanks!
Title: Re: Window pollEvents() causing lag when joystick not plugged in.
Post by: DarkRoku12 on May 16, 2016, 12:39:28 am
This is very weird problem, but first you and us need to know if the problem is SFML or your code.

Try this sample code from sfml visual studio tutorial.

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}

 

If you want, add little event handling to test.
And give your result here.

Is useful to know what version of SFML you are using, your OS and your PC specifications.

PD: If you are using "if", check semi-colon error like:
            if (event.type == sf::Event::Closed); // -> note the wrong semi-colon here.
                window.close();
 

Or if using "switch", for missing-break errors:

   
switch( event.type )
{

  case sf::Event::Closed :
        window.close() ;
       // Missing break here.
  case sf::Event::AnyEvent :
         any_action() ;
         break ;

}
 
Title: Re: Window pollEvents() causing lag when joystick not plugged in.
Post by: Mr_Blame on May 16, 2016, 02:26:11 pm
For some people will work:
1.) remove joystick event polling from SFML source
2.) compile SFML source
That is beacause of some weird event polling on some windows versions.