Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Window pollEvents() causing lag when joystick not plugged in.  (Read 2352 times)

0 Members and 1 Guest are viewing this topic.

SamHenry97

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
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!

DarkRoku12

  • Full Member
  • ***
  • Posts: 203
  • Lua coder.
    • View Profile
    • Email
Re: Window pollEvents() causing lag when joystick not plugged in.
« Reply #1 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 ;

}
 
« Last Edit: May 16, 2016, 12:48:45 am by DarkRoku »
I would like a spanish/latin community...
Problems building for Android? Look here

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: Window pollEvents() causing lag when joystick not plugged in.
« Reply #2 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.