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

Author Topic: Effect of no setFramerateLimit  (Read 899 times)

0 Members and 1 Guest are viewing this topic.

mujina

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Effect of no setFramerateLimit
« on: January 14, 2021, 05:42:49 pm »
Hi!

Can someone shed some light on how a game would behave when window.setFramerateLimit is not set?

I was running a very simple game and I accidentally commented out the line in which I was setting the framerate limit, and when I run it it appeared to be stuck. The first time it froze my entire screen (I had to Ctrl-Alt-F2, find the process and kill it. I'm on linux). The second time, the window appeared but that was frozen (the rest of my applications was not). The third time I run it, I didn't even see the window.

My program is something along these lines

RenderWindow window{{windowWidth, windowHeight}, "Title"};
// window.setFramerateLimit(120);
while(true){
    window.clear(Color::Black);
    Event event;
    int eventPerFrame {0};
    while(window.pollEvent(event)){
        if (event.type == Event::Closed) {
            window.close();
            break;
        }
    }
    if(Keyboard::isKeyPressed(Keyboard::Key::Escape)) break;
    // update logic here
    window.display();
}
 

Also, if I put some logging in the game loop, I don't see anything. It seems that it gets stuck at the event polling.

I'd like to understand if setFramerateLimit is mandatory and why apparently without that my program gets stuck at the polling.

[It's my first post here. Please let me know if I missed some rule of the etiquette or if I should do something differently].

Thank you!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10825
    • View Profile
    • development blog
    • Email
Re: Effect of no setFramerateLimit
« Reply #1 on: January 14, 2021, 07:36:24 pm »
If you don't limit the framerate and your GPU preferences don't enforce vsync (or similar), the application will just run as fast as it possibly can.
This often leads to high CPU and GPU loads and depending on the GPU, you'll even hear some coil whining.

It shouldn't really freeze the application, but I'm also not sure whether the high CPU load can cause some side-effects or the many calls to the event processing will DDoS the X server or similar.
Either way, it's recommended to limit the framerate in some way.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/