SFML community forums

Help => Window => Topic started by: Tukimitzu on April 03, 2016, 07:02:57 am

Title: Poll Event issues
Post by: Tukimitzu on April 03, 2016, 07:02:57 am
Briefly put, the issue is this: a few seconds after having the program running, the pollEvent function in one of its iterations takes a long time (more than 1 second) to do whatever it does.

1) This lag spike happens only once in the entire execution, and it only happens some time within the first 5 seconds of execution. It will run normally after that.

2) I had this problem with SFML 2.0 and now with SFML 2.3.2.

3) I'm using sf::RenderWindow.

This is the code:
...
    while(window.isOpen()){
        sf::Event ev;
        sf::Clock cl;
        while(window.pollEvent(ev)){
            printf("ev.type = %d took %.6fs\n", ev.type, cl.restart().asSeconds());
            if (ev.type == sf::Event::Closed){
                window.close();
            }
        }
    }
...

First execution:
(http://i.imgur.com/zNA4oEl.png)

Second execution:
(http://i.imgur.com/5Su34W0.png)

Third execution:
(http://i.imgur.com/RzA5Tzd.png)

Detailed description: I run the executable, it opens the window and runs the code fine, display whatever it has to display, 2-5 seconds after started, the lag spike happens. It doesn't matter if I let the mouse resting on screen or off-screen, if I don't move the mouse during this first 5 seconds, the next time I move the mouse, the lag spike will happen, 100% of the times.

I'm running Windows 10 and MinGW-4.9.3 compiler, although it also happened when using Windows 8.1 and some other previous MinGW version that I can't recall.

Thanks for helping!
Title: Re: Poll Event issues
Post by: Laurent on April 03, 2016, 08:31:40 am
Obvious question (sorry): are you sure that something's happening during this freeze? Because if there's no event, it's perfectly normal that the event loop is not executed ;D

Have you tried to reproduce the problem with a minimal code?
Title: Re: Poll Event issues
Post by: Mr_Blame on April 03, 2016, 01:13:20 pm
I think it is sf::clock causing it I have noticed it when I was making time synchronized game.
Title: Re: Poll Event issues
Post by: victorlevasseur on April 03, 2016, 02:54:12 pm
The problem of your test program is that if pollEvents returns false, the while loop is not executed. If it happens for multiple frames, the clock keeps running and is also reset when an event is caught.
Title: Re: Poll Event issues
Post by: Tukimitzu on April 03, 2016, 05:31:14 pm
Since I create the sf::Clock right before the pollEvent call and print and reset it right after the call, there's only one function that can be taking that long to return, am I missing something?


If the while(pollEvent) returns false for multiple frames, it doesn't matter because the clock will always reset before it is called.

The code is pretty minimal already, after your suggestion, I even commented the rest of the loop, but I don't think the rest of the code matters, because as I said, the sf::Clock is always reset.


Hmm....
Title: Re: Poll Event issues
Post by: victorlevasseur on April 03, 2016, 05:34:52 pm
Yes, you're right, did not see the sf::Clock declaration.
Title: AW: Poll Event issues
Post by: eXpl0it3r on April 03, 2016, 07:12:28 pm
Get debug libraries, start the debugger and/or profilee and see what's going on.

Do you have any game pads plugged in?