Seemingly random frameRate drop when no code is added

I have been putting up with this for a while now, but it’s becoming really annoying. I’m on MSVC 2008 doing a really simply project. I’m prototyping an iPhone app, so everything is really low-end and basic. Just a few ofImages for a background and some button textures, and a little text box with some sample text in it. My frameRate is set at 60fps, but out of nowhere, usually after I’ve been working for a little while, it drops to about 30fps. And this comes without me adding anything major or changing any of the base code. Sometimes it eventually jumps back up to 60fps, then back down to 30fps. Usually after I’m done working and I shut down my system for the night, I’ll get up the next morning, boot everything up, and start working, and boom, I’m debugging at 60fps again.

Anybody have a clue what could be causing something like this to happen? The frameRate drop doesn’t occur while the program is running, but it will switch each time I run it. Sometimes it’s 60fps, sometimes it’s 30fps. I’ve tried running the code in Xcode and in the iPhone simulator, and I never get the frameRate problems there. I know this is kind of vague, but I’m just wondering if anyone has an idea off the top of their head.

if you have vertical sync enabled on your card, your frame rate will have to be a multiple of 60, since it’s locking to the refresh of the screen (typically, 60hz). therefore, if you are not able to porduce images at 60 fps, you will drop down to 30fps. it’s annoying yes, but it means the images are not tearing. You can disabled vertical sync, and have frame rates of 30, 40, 50, etc. by defaults macs (don’t know about iphone) have vsync off by default so you likely don’t see it (but you can then see frame rates of 300 fps, etc if you don’t set the frame rate)

you can :

a) disable vertical sync on the graphics card (called async or vertical blanking) or in code, but note that the card preferences overwrite the application so be careful. on windows right click desktop->properties->display->advanced settings (off the top of my head)

b) write frame independent code. for example, instead of doing

x = x + 1;

ever frame, calculate the elapsed time, like:

x = x + constant * elapsedTimeInTheLastFrame

so, if you are running at a faster frame rate, the elapsed time is less, so you take shorter steps, if you slow down, you take larger steps.

I hope that helps ! both (a) and (b) are valid options and you are hitting a common problem with graphics programming, so hopefully don’t get too frustrated…

take care,
zach

ps: some infos here:

http://www.gamedev.net/reference/articl-…-le1382.asp
http://www.gamedev.net/reference/articl-…-le1604.asp
(disable vsync on intel graphics) http://www.intel.com/support/graphics/sb/cs-004692.htm

OK, thanks zach. Good to know. I’ll give it a try. My graphics card’s preference panel says that “Wait for vertical refresh” is “Off, unless application specifies.” So I guess that means that I need to disable it in my code.

OK I tried turning off vertical sync in both the code and on the graphics card, and I’m still getting the same result. 32fps when the frameRate is set to 60fps. I’m not sure it’s worth changing all my movement to the frame-independent code you described above since I know it’ll work on the mac. I might just have to live with it until I start working exclusively on the iPhone simulator.

sounds like it could be a memory leak. watch the memory usage of your app over time, if it’s increasing then you’re leaking memory. this will cause the operating system to start thrashing around as it tries to allocate virtual memory for you.

another possibility is you’re creating a denormal-bug situation. do you have a float or a bunch of floats that are decreasing to tiny tiny values? google denormal bug for more information.

hth
d

do you have antivirus or windows update running in background? :stuck_out_tongue:

Yes. I have an easing routine:

  
  
float dy = tbox_targetY - tboxY;  
if(fabs(dy) > 1){  
     tboxY += dy * 0.05;  
}  
  

Yes! I guess you’re implying I should try disabling that before running the program…

Yes. I have an easing routine:

  
>       
>     float dy = tbox_targetY - tboxY;  
>     if(fabs(dy) > 1){  
>          tboxY += dy * 0.05;  
>     }  
>       
>     

hmm - that might be it, although i’d expect the ‘>1’ check would kill the denormal effect. try the solution/s mentioned here and see if they help:
http://www.music.columbia.edu/cmc/music-…-#denormals