SFML community forums

Help => General => Topic started by: szpaq234 on April 09, 2016, 05:06:38 am

Title: window.poll() lags on my desktop PC
Post by: szpaq234 on April 09, 2016, 05:06:38 am
window.poll() sometimes gets stuck. What exactly happens is program spins in the while loop and occasionally window.poll() takes up to 7s !!! to execute. Below is minimal code that causes the problem and as you can see, there's nothing that would interfere with the window even remotely. It seems that sfml doesn't like my PC. This happens only on my desktop running Win10. It work normally on my laptop that also runs win10. Any thoughts ?

I did a quick test, no event is actually being caught during the lag.

#include <SFML/Graphics.hpp>
#include <chrono>

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
    while (window.isOpen())
    {
        std::chrono::milliseconds t1 = std::chrono::duration_cast<std::chrono::milliseconds>
            (std::chrono::system_clock::now().time_since_epoch());

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

        std::chrono::milliseconds t2 = std::chrono::duration_cast<std::chrono::milliseconds>
            (std::chrono::system_clock::now().time_since_epoch());
        int dur = (int)((t2 - t1).count());
        if (dur > 20)
            printf("%d\n", dur);

        window.clear(sf::Color::Black);
        window.display();
    }

    return 0;
}
 
Title: Re: window.poll() lags on my desktop PC
Post by: Mr_Blame on April 09, 2016, 08:15:12 am
What about configuration of your pc (e.g. how many bits, which os, ram etc.). "desktop pc" doesn't give much information  ;).
Title: Re: window.poll() lags on my desktop PC
Post by: szpaq234 on April 09, 2016, 09:07:34 am
On both machines I run SFML in 64bit mode with DLLs. I mentioned OS. Only hardware that can impact this in any way is Radeon R9 on my desktop.
Title: AW: window.poll() lags on my desktop PC
Post by: eXpl0it3r on April 09, 2016, 09:55:14 am
Do you have a gamepad plugged in?

Get the debug libraries and run it in a profiler/debugger to figure out where it gets stuck.
Title: Re: window.poll() lags on my desktop PC
Post by: szpaq234 on April 09, 2016, 07:24:38 pm
It might be it. I unplugged and it works normally. That would also explain why it works normally on my laptop.
Title: Re: window.poll() lags on my desktop PC
Post by: Mr_Blame on April 09, 2016, 10:59:07 pm
win32 api's fault :P