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

Author Topic: Set Frame Rate Limit Not Working Even With Vertsync On  (Read 6334 times)

0 Members and 1 Guest are viewing this topic.

Zee

  • Newbie
  • *
  • Posts: 12
    • View Profile
Set Frame Rate Limit Not Working Even With Vertsync On
« on: May 24, 2012, 04:28:43 am »
Hi,

I've encountered a problem recently which sounds like a common problem with SFML. My frame rate limit is set at 60, but the FPS is usually around ~50, but sometimes jumps to ~100. Without the framerate limit it can go as high as 2000 so I'm sure it's not hardware limitations.

I did some searching and it seems like turning vertical sync to true would usually fix the issue, however the problem is I already did that. The more amazing part is that sometimes it works and sometimes it doesn't. I would move my code

App.setVerticalSyncEnabled(true);
App.setFramerateLimit(60);

around and almost randomly it would work again in different spots of the code, but if I change parts of the code then it would stop working again. The weird part is if I undo the changes I made to break the code, it would remain broken, even if it worked earlier.

I thought it may have been outdated SFML issue, so I went ahead and got the sfml 2 RC and the issue is still present. I'm running out of ideas on how to fix this.

Anything would help me at this point, I am finalizing a large project and months of work right now. Thank you very much for your time!

EDIT: Here's a sample output of FPS that I get.

http://i.imgur.com/R5ZmP.jpg

The way I calculated FPS was to count an integer every frame, and when clock as seconds = .5, then take that number and double that number to get the FPS, then reset it for the next round. It basically calculates the frames per .5 seconds, then double it. Should be fairly accurate, shouldn't be off by too much anyways.
« Last Edit: May 24, 2012, 04:44:20 am by Zee »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Set Frame Rate Limit Not Working Even With Vertsync On
« Reply #1 on: May 24, 2012, 07:56:51 am »
Can you show a complete and minimal code that reproduces the problem?
Laurent Gomila - SFML developer

Zee

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Set Frame Rate Limit Not Working Even With Vertsync On
« Reply #2 on: May 24, 2012, 08:31:46 am »
Hello Laurent,

I tried to recreate the problem using minimal code, but I cannot. The problem at first glance seems to go away as I delete away parts of the irrelevant code (which doesn't make any sense to me). Here's a brief description of how the program works:


Quote
Within main:
start render window, set options, etc.

int z =0
while renderwindow is open
{


if z = 0
{... draw stuff
}
else if z = 1
{... draw other stuff
}

......

else if z = 360
{...
}

render window display
}

the entire program is a linear sequence of events, labeled by integer z. Once an event is finished, z++, so the next event will start. There's a total of around 8200 lines of code and around 360 events. As a test I deleted all the events except for the first 3 (so z only goes to 2), now it has around 1200 lines of code, and the FPS stabilized at around 65.

Perhaps this is a programming issue unrelated to SFML, but I feel like changing the code there, which was unused in testing in the first place, should not have affected anything. I literally just deleted parts of the code that wasn't even used and the problem seemed to go away.

Also, like earlier, the problem seems to come and go. Sometimes it just fixes itself for no reason and breaks again later. This also may be one of those occurrences.

Sorry for being vague. It's still definitely broken when all put together. I will read over my code again (I already have several times), I don't think I will find anything new however. Thanks for the fast reply and please let me know if you have any idea what might be causing this. Thank you!


EDIT: I kept trying new things to get it to work, here's the funny part. I literally just made a new project, copy pasted all the code and resource files over, and it seems to work perfectly stable now at around 63 FPS. However I'm afraid to make any changes to the code since usually it would end up breaking it irreversibly. Perhaps this sheds some light to the real problem at hand?
« Last Edit: May 24, 2012, 08:36:52 am by Zee »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Set Frame Rate Limit Not Working Even With Vertsync On
« Reply #3 on: May 24, 2012, 08:38:26 am »
I have no idea what can be wrong in your code, sorry. But I really feel like it's not related to SFML; if it was, you would most likely be able to reproduce the problem with a simple code.
Laurent Gomila - SFML developer

Zee

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Set Frame Rate Limit Not Working Even With Vertsync On
« Reply #4 on: May 24, 2012, 09:03:53 am »
Hello Laurent,

Not to my surprise, I ended up recreating the problem with minimal code, the results are pretty daunting:

#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <iostream>
#include <sstream>

int main()
{
    sf::Clock clock;
    sf::RenderWindow App(sf::VideoMode(1280, 800, 32), "window");
    App.setFramerateLimit(60);
    App.setVerticalSyncEnabled(true);

    //Intro Resources



//Important global variables

//Menu sequence variables

//Game sequence variables

//Text data
int timer =0;
int frames =0;
//GAME STARTS
    while (App.isOpen())
    {
        if (clock.getElapsedTime().asSeconds() >= .5)
        {
            std::cout<<frames*2<< "\n";
            frames=0;
            clock.restart();
        }

        App.clear();
        sf::Event Event;

        if (App.pollEvent(Event))
        {
            if (Event.type == sf::Event::Closed)
                App.close();
        }
        frames++;
        App.display();
    }

    return 0;
}
 

It basically is a "hello world" program for SFML, it makes a render window, and nothing else. The frames don't spike to 100s, but it stays around 50s much like what the old broken program did when idle. Here's an output of FPS:

http://i.imgur.com/VkqRJ.jpg

Capped at 60 it should return something like 63ish from experience, and without the limit it goes to the 1000s so I know it's not a hardware issue.

Like I said, this issue comes and goes, it's quite unstable and I'm really not sure what's going on anymore. using the same exact code in another project, it would work fine.
« Last Edit: May 24, 2012, 09:26:44 am by Laurent »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Set Frame Rate Limit Not Working Even With Vertsync On
« Reply #5 on: May 24, 2012, 09:28:06 am »
Framerate limit and vertical sync should never be activated together.
Laurent Gomila - SFML developer

Zee

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Set Frame Rate Limit Not Working Even With Vertsync On
« Reply #6 on: May 24, 2012, 03:37:13 pm »
Hmm okay, how should I do it then so that it would work? I'm not too familiar with how they should be activated. Thanks!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Set Frame Rate Limit Not Working Even With Vertsync On
« Reply #7 on: May 24, 2012, 03:38:10 pm »
Quote
Hmm okay, how should I do it then so that it would work?
Choose either one or the other... simply :P
Laurent Gomila - SFML developer

Zee

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Set Frame Rate Limit Not Working Even With Vertsync On
« Reply #8 on: May 24, 2012, 03:43:44 pm »
If I delete vertical sync, it still would not change anything. If I delete frame rate limit, then there would be no limit and FPS will be around 1000. I read on some of the forums that the way to fix it would be activating vertical sync in addition to limiting frames?

EDIT: Example of supposed solution: http://www.gamedev.net/topic/567471-sfml-setframelimit-not-limiting-frame-rate/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Set Frame Rate Limit Not Working Even With Vertsync On
« Reply #9 on: May 24, 2012, 03:47:39 pm »
Quote
If I delete frame rate limit, then there would be no limit and FPS will be around 1000
So vertical sync is probably forced to "off" in your graphics driver settings. It should be "controlled by applications".

Quote
I read on some of the forums that the way to fix it would be activating vertical sync in addition to limiting frames?
This is wrong. They tend to interact badly and can produce low framerate, rather than making it more consistent.
Laurent Gomila - SFML developer

Zee

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Set Frame Rate Limit Not Working Even With Vertsync On
« Reply #10 on: May 24, 2012, 03:50:24 pm »
Hmm should I be attempting to change my graphics driver settings then in that case?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Set Frame Rate Limit Not Working Even With Vertsync On
« Reply #11 on: May 24, 2012, 03:55:04 pm »
Yes, that's what I meant.
Laurent Gomila - SFML developer

Zee

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Set Frame Rate Limit Not Working Even With Vertsync On
« Reply #12 on: May 24, 2012, 04:02:51 pm »
Alright I will play around with my driver settings. Thank you very much for your help!

Zee

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Set Frame Rate Limit Not Working Even With Vertsync On
« Reply #13 on: May 27, 2012, 05:41:59 pm »
Hello,

I played around with my graphics drivers and did an entire system update on everything, still this is a problem for me. My graphics card is ATI Radeon HD 5670 and I'm using Code::Blocks

However, I found something very interesting. If I use a win32 GUI project, and copy the code to a new project, and all the resources, then it would fix the problem on the first try building and running the project, but if I run the compiled release .exe file in my bin folder, then it would break it. Compiling it again under SFML would fix it again.

This issue isn't as much of a problem using a console application project, but it still happens.

Sometimes it's broken to the point where even compiling it again would not fix it, but then all I need to do is make a new project with the same code and resources and it would work again.


I'm a beginner programmer so I really don't know what's going on here and how I can fix it. Does anyone know anything about this issue? If not, does anyone know where I can go to seek help on this issue? Thank you very much for your help.

EDIT: I've noticed that the issue tends to appear more often if I go watch videos online or something. For example, the program will run fine, but if I go and watch a youtube video, then come back and run the same exe file again, it would have FPS issues, and it won't be fixed until I make a new project and recompile it again. I have no clue what to do or even who to ask to solve this issue.


EDIT #2: Something else I realized, when it doesn't work (FPS issue present), then when I quit my program, it would not return 0. When it works fine, it returns 0 when I quit. When the FPS issue is present, main() returns something like -2147418113 <0x8000FFFF>, does that mean anything? Thanks again.
« Last Edit: May 27, 2012, 08:06:30 pm by Zee »

 

anything