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

Author Topic: Unstable frame rate  (Read 3226 times)

0 Members and 1 Guest are viewing this topic.

ItsAme

  • Newbie
  • *
  • Posts: 2
    • View Profile
Unstable frame rate
« 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:
 
  • I make a new Visual Studio 2015 C++ Application and add SFML 2.3.2 as a dependency.
  • I'm using the new nuget package manager to achieve this and never had any problems before.
  • Afterwards I copy the example code in the main.cpp file, add some frame time measurement logic
       and print it. No custom code or whatsoever.

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.
« Last Edit: May 08, 2016, 09:34:10 am by ItsAme »

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: Unstable frame rate
« Reply #1 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());
}
« Last Edit: May 08, 2016, 12:56:15 pm by Mr_Blame »

ItsAme

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Unstable frame rate
« Reply #2 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.

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: Unstable frame rate
« Reply #3 on: May 08, 2016, 01:23:40 pm »
than try reinstalling SFML.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Unstable frame rate
« Reply #4 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.

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: Unstable frame rate
« Reply #5 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?
« Last Edit: May 08, 2016, 03:09:24 pm by Mr_Blame »