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

Author Topic: Poll Event issues  (Read 4234 times)

0 Members and 1 Guest are viewing this topic.

Tukimitzu

  • Full Member
  • ***
  • Posts: 117
  • Anti-Hero Member
    • View Profile
Poll Event issues
« 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:


Second execution:


Third execution:


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!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Poll Event issues
« Reply #1 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?
Laurent Gomila - SFML developer

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: Poll Event issues
« Reply #2 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.

victorlevasseur

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Poll Event issues
« Reply #3 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.

Tukimitzu

  • Full Member
  • ***
  • Posts: 117
  • Anti-Hero Member
    • View Profile
Re: Poll Event issues
« Reply #4 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....

victorlevasseur

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Poll Event issues
« Reply #5 on: April 03, 2016, 05:34:52 pm »
Yes, you're right, did not see the sf::Clock declaration.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: Poll Event issues
« Reply #6 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?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/