SFML community forums

Help => General => Topic started by: ItsAme on May 08, 2016, 09:28:49 am

Title: Unstable frame rate
Post by: ItsAme on May 08, 2016, 09:28:49 am
I'm currently experiencing a very strange and annoying problem:

When using SFML, one frame every second is very slow.
What I did:
 
main.cpp:

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

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

                float elapsedTime = clock.getElapsedTime().asSeconds();
                                if(elapsedTime > 0.040) {
                                        printf("%f\n", elapsedTime);
                                }
                                clock.restart();

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

        return 0;
}

The slow frame usually needs between 60 and 100ms and appears (exacly) once every second. I'm using sfml since 3 years and never had this issue before. The problem also appears when I comment everything except the window.displace() command.

I'm using Windows 10 and there are no other processes running in the background that might cause this issue. It also happens on other PCs.
Title: Re: Unstable frame rate
Post by: Mr_Blame on May 08, 2016, 12:43:02 pm
Fps is computed in other way... You are computing something not right.

EDIT:

Here is function from SFML-wiki for fps computing
float getFPS(const sf::Time& time) {
     return (1000000.0f / time.asMicroseconds());
}
Title: Re: Unstable frame rate
Post by: ItsAme on May 08, 2016, 01:14:27 pm
My logic works the same. I just use seconds instead of micros to avoid the division. (Also, I don't calculate the fps but the elapsed time since the last frame which should be about 17ms @ 60fps).

Since the slow frame needs up to 100ms, I can also visually see the lag when moving around elements on the screen. So it's definitly a problem and not a false alarm.
Title: Re: Unstable frame rate
Post by: Mr_Blame on May 08, 2016, 01:23:40 pm
than try reinstalling SFML.
Title: Re: Unstable frame rate
Post by: Jesper Juhl on May 08, 2016, 01:56:40 pm
than try reinstalling SFML.
And how would that help anything?

Before a solution can be suggested the problem must be understood.
Title: Re: Unstable frame rate
Post by: Mr_Blame on May 08, 2016, 03:00:13 pm
Before a solution can be suggested the problem must be understood.
Truly speaking I don't see anything slow in this code, it is a default SFML example(except some clock realted code). He also mentioned that it slows down on other PCs... That means that problem lies somewhere else except code e.g some drivers etc., but it this program slows down on other PCs and that is weird...

EDIT:

ItsAme, are your drivers up-to-date? What is your PC configuration?