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

Author Topic: Different framerate in Visual Studio and Explorer  (Read 19069 times)

0 Members and 1 Guest are viewing this topic.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Different framerate in Visual Studio and Explorer
« 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?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Different framerate in Visual Studio and Explorer
« Reply #1 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?
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Different framerate in Visual Studio and Explorer
« Reply #2 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 ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Different framerate in Visual Studio and Explorer
« Reply #3 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
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Different framerate in Visual Studio and Explorer
« Reply #4 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
« Last Edit: April 30, 2012, 04:37:57 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Rosme

  • Full Member
  • ***
  • Posts: 169
  • Proud member of the shoe club
    • View Profile
    • Code-Concept
Re: Different framerate in Visual Studio and Explorer
« Reply #5 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!
GitHub
Code Concept
Twitter
Rosme on IRC/Discord

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Different framerate in Visual Studio and Explorer
« Reply #6 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.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Different framerate in Visual Studio and Explorer
« Reply #7 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... :/
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: