SFML community forums

Help => Window => Topic started by: Nexus on April 30, 2012, 12:07:23 pm

Title: Different framerate in Visual Studio and Explorer
Post by: Nexus on April 30, 2012, 12:07:23 pm
I have an application which I limit to 40 frames by calling sf::Window::setFramerateLimit(). When I start the application from Visual Studio 2010, it works well, however the .exe started from Windows Explorer seems to run at ~33 FPS, or at ~37 FPS if VSync is enabled. The same result comes up when I manually call sf::Sleep(). With a busy-wait loop I achieve the 40 FPS even outside Visual Studio, but I hate to let the processor core work at capacity if only a few percents are required.

An idea why these different framerates occur? And what's the best approach to fix that?
Title: Re: Different framerate in Visual Studio and Explorer
Post by: Laurent on April 30, 2012, 01:02:02 pm
From Visual Studio, are you sure that you run the application without the debugger (Ctrl+F5, not F5)?

Is it a release or debug build?
Title: Re: Different framerate in Visual Studio and Explorer
Post by: Nexus on April 30, 2012, 01:42:16 pm
Yes, but both F5 and Ctrl+F5 lead to the same result. It is Release mode. And the framerate is far away from the maximum, I reach ~500 FPS without a frame limit.

In case there's no easy fix, I'm currently trying to implement a dynamically controlled sleep - that is, measure frame rate and if it is too low, decrease the sleep time ;)
Title: Re: Different framerate in Visual Studio and Explorer
Post by: Laurent on April 30, 2012, 02:40:06 pm
But it's very strange that the behaviour is not the same inside and outside VS. It would be cool to find out why ;D
Title: Re: Different framerate in Visual Studio and Explorer
Post by: Nexus on April 30, 2012, 04:31:34 pm
Indeed. It seems to be something more complex, a simple example couldn't reproduce it. In the following code, the result is always the same in VS and Explorer.
#include <SFML/Graphics.hpp>
#include <sstream>
#include <iostream>

int main()
{
        sf::RenderWindow window(sf::VideoMode(640, 480), "SFML Application");
        window.setFramerateLimit(50);

        sf::Clock clock;
        int frames = 0;

        sf::Text text;

        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::KeyPressed
                         || event.type == sf::Event::Closed)
                                return 0;
                }

                window.clear();
                window.draw(text);
                window.display();

                ++frames;
                if (clock.getElapsedTime() > sf::seconds(1))
                {
                        std::ostringstream stream;
                        stream << frames;
                        std::cout << frames << "\n";
                        text.setString(stream.str());
                        frames = 0;
                        clock.restart();
                }
        }
}

However, the strange thing is, either I always get ~50 FPS as expected, or always ~33 FPS. Upon observing it a bit more, it depends on whether I watch a YouTube video/listen to music (then it is 50 FPS) or not (33 FPS)... :o

Seriously, WTF? Anyway, I'll update my drivers... And see if there's a spider walking over my motherboard :P
Title: Re: Different framerate in Visual Studio and Explorer
Post by: Rosme on April 30, 2012, 09:27:10 pm
Seriously, WTF? Anyway, I'll update my drivers... And see if there's a spider walking over my motherboard :P
Spider are not bugs, so it can't be the cause...maybe more like a fly or an ant...ok I'm outta here with my bad jokes!
Title: Re: Different framerate in Visual Studio and Explorer
Post by: Mario on May 05, 2012, 12:52:26 pm
Make sure you disable VSync before doing the testing. From my experience, Windows might slow down the framerate of programs running in windowed mode to 60 fps, 30 fps or 15 fps (whatever is closest to/right below current framerate) when VSync is enabled. That would explain the slow down when playing something on YouTube.
Title: Re: Different framerate in Visual Studio and Explorer
Post by: Nexus on May 06, 2012, 03:59:24 pm
With the code shown above, the result was independent of VSync. Also, at setFramerateLimit(60) the framerate was indeed ~60 FPS... :/