Sign in to follow this  
pacifistcottage

Frame rate randomly locks at 48 FPS (PC)

Recommended Posts

Hi all,

Long-time lurker, but first-time poster. I am hoping someone can shed some light on an issue that is making me want to punch things.

Basically, one of the PCs on which I do XNA development is having frame rate issues, seemingly randomly. I am working on a 2d side-scrolling platformer kind of game, and [i]sometimes[/i], with no warning, the frame rate will suddenly just drop and lock to 48 FPS. So, a few important points:

[list][*]When the game is running at 60FPS, Task Manager shows CPU usage at nearly nothing--between 1 and 3%. However, once the drop to 48 happens, CPU usage locks in at around 25%. Once it drops, it never goes back up. I just have to restart the game (sometimes it even does the 48 FPS thing immediately upon loading)[*]The level I am testing on is built from Tiled maps, and scripted. There is no random generation of anything going on, and everything should be more or less exactly the same every single time I play it, which is why I say this is happening randomly. It also happens at random times, not like, when loading new maps or creating enemies or anything[*]The PC I am working on is WAY overpowered to be having performance issues with this. It's not top of the line, but it's an i5, 8GB RAM, ATI 5770. I do [i]plenty[/i] of gaming with pretty intensive games (not to mention other XNA games, like Terraria and Capsized) on it and it never breaks a sweat.[*]I can run the game on another machine, and it has no serious frame rate issues--usually sticks between 55 and 60 FPS (and it is a slower machine).[/list]
I assumed I had made a mistake somewhere in my code and left a faulty loop running somewhere or something, but then I tested another developer's game on my machine, and the [i]exact[/i] same thing happened. The game just throttled to 48 FPS. The fact that it happened in more than one game, both XNA, leads to believe something is amiss with my system, rather than my code.

Is this anything anyone has ever heard of? I updated my graphics drivers, Win 7 64 is all up to date, A/V up to date, etc. I also tried disabling vsync, thinking maybe it was trying to lock to a defective monitor or something, but it made no difference. Any ideas?

Could it be an IRQ issue, maybe with a wireless internet dongle or FireWire audio interface (admittedly, I don't know a whole lot about about how video cards deal with other system hardware)? It is driving me [i]insane[/i], when I am testing new code in my game and the frame rate just randomly drops.

Any ideas would be appreciated. Thanks a bunch!

Share this post


Link to post
Share on other sites
How is it that when the game is at 60Fps, Task Manager shows 1-3% CPU usage? Seems to me you're using Sleep(). That's just wrong (because if you call Sleep(16) it will guarantee you it will sleep for A MINIMUM of 16 miliseconds; it may actually take more time).
And don't even think about calling Sleep(0); that's just worse.

Share this post


Link to post
Share on other sites
[quote name='Matias Goldberg' timestamp='1317869495' post='4869637']
How is it that when the game is at 60Fps, Task Manager shows 1-3% CPU usage? Seems to me you're using Sleep(). That's just wrong (because if you call Sleep(16) it will guarantee you it will sleep for A MINIMUM of 16 miliseconds; it may actually take more time).
And don't even think about calling Sleep(0); that's just worse.
[/quote]

Nope, no calls to Sleep(), unless one of the XNA classes has calls to it built-in. None by me, though.

To clarify: I am fairly early in development, so there is not a whole lot going on the game (hence the low CPU usage), and these figures are based on doing nothing at all--just standing there. I guess, taking another look, it's more like 3-5% on average when not doing anything, but the point is it still jumps up the 48 FPS/25-ish%, as compared to 60 FPS/3-5%, so obviously something is wrong.

Typically, I wouldn't worry about performance this early in development, but as I said in my OP, it seems to be a system issue, rather than an issue with my code, because the same thing was happening in another game I tried.

Share this post


Link to post
Share on other sites
[quote name='Matias Goldberg' timestamp='1317869495' post='4869637']
How is it that when the game is at 60Fps, Task Manager shows 1-3% CPU usage? Seems to me you're using Sleep(). That's just wrong (because if you call Sleep(16) it will guarantee you it will sleep for A MINIMUM of 16 miliseconds; it may actually take more time).
And don't even think about calling Sleep(0); that's just worse.
[/quote]

Vertical sync

Share this post


Link to post
Share on other sites
So here's a small update, and it makes me even more confused. Perhaps I am just misunderstanding XNA's Update/Draw hierarchy, but I am baffled. This is with IsFixedTimeStep set to false, and VSync set to true (but it doesn't change anything if I turn it off).

If I print gameTIme.ElapsedGameTIme to the Console during Update and Draw, it is showing a steady .0166667 every single frame, even when the game is running at 48/49 FPS. (I am using Fraps to display the FPS, but you can also visibly see that the game is running slower just by playing.)

So, maybe I am missing something obvious here. Why would it be running at 48/49 FPS when ElapsedGameTime is showing a consistent 16ms (i.e. 60 FPS)? For what it's worth, one sure-fire way to make the frame-rate drop is to click out of the game on another window and back into the game. This will make it happen every single time (although even if you don't do that, it still happens randomly while you're playing).

Share this post


Link to post
Share on other sites
[quote]
This is with IsFixedTimeStep set to false, and VSync set to true (but it doesn't change anything if I turn it off).
[/quote]
VSync can often be "forced" on or off in the graphics driver. Open your graphics driver configuration screen, you may find a setting where you can change VSync to "application controlled", or just force it off temporarily while testing.

Share this post


Link to post
Share on other sites
[quote name='rip-off' timestamp='1317892259' post='4869715']
[quote]
This is with IsFixedTimeStep set to false, and VSync set to true (but it doesn't change anything if I turn it off).
[/quote]
VSync can often be "forced" on or off in the graphics driver. Open your graphics driver configuration screen, you may find a setting where you can change VSync to "application controlled", or just force it off temporarily while testing.
[/quote]

Ok, I will check that out. I looked briefly last night, but did not have enough time for a thorough check. That does seem like the kind of thing that is going on here, though. I'll report back once I get a chance to test it.

Thanks a bunch for the suggestion!

Share this post


Link to post
Share on other sites
It could be that something that happens during gameplay causes the game to become CPU bound (e.g. it starts doing an expensive calculation every frame). I'd suggest using a CPU profiler when it's running with the high CPU usage to find out if that's what is happening, and if so where.

Share this post


Link to post
Share on other sites
[quote name='Adam_42' timestamp='1317910611' post='4869782']
It could be that something that happens during gameplay causes the game to become CPU bound (e.g. it starts doing an expensive calculation every frame). I'd suggest using a CPU profiler when it's running with the high CPU usage to find out if that's what is happening, and if so where.
[/quote]

That's a good call, and reminds me of the time I had added extra objects to my draw lists for each frame, but had managed to let a bug creep in where they didn't get removed for up to maybe 10 frames or so. Cue escalating frame times and mysterious performance loss until I tracked it down.

Might also be worth doing a before and after comparison of your API calls using something like PIX (or whatever the XNA equivalent is) just to confirm that the same isn't going on here too.

Share this post


Link to post
Share on other sites
[quote name='mhagain' timestamp='1317918094' post='4869814']
[quote name='Adam_42' timestamp='1317910611' post='4869782']
It could be that something that happens during gameplay causes the game to become CPU bound (e.g. it starts doing an expensive calculation every frame). I'd suggest using a CPU profiler when it's running with the high CPU usage to find out if that's what is happening, and if so where.
[/quote]

That's a good call, and reminds me of the time I had added extra objects to my draw lists for each frame, but had managed to let a bug creep in where they didn't get removed for up to maybe 10 frames or so. Cue escalating frame times and mysterious performance loss until I tracked it down.

Might also be worth doing a before and after comparison of your API calls using something like PIX (or whatever the XNA equivalent is) just to confirm that the same isn't going on here too.
[/quote]

Yeah, I will check this out as well, although it seems slightly less likely in this particular instance, since the issue is really only occurring on a single machine, and happens with my own game plus another developer's game. I will test all of these options, though, and I really appreciate the suggestions, so thank you all very much!

Does anyone have a recommendation for a good profiler for XNA 4? I tried a few out yesterday, but didn't have a lot of success, as most of the ones I found did not work well with .NET 4. (To be fair, I did not try PIX, because I didn't want to download the entire DX SDK just to get it, but if that is "the one to try," I will gladly do it.)

Thanks again!

Share this post


Link to post
Share on other sites
So unfortunately, none of this helped. I did find a setting in my video card control panel to completely disable vsync, but it didn't help. I have basically gone from frustrated to hopeless at this point...

Also, to prove I'm not completely off my rocker, I took a fun little screenshot. I made a brand new game and did NOTHING to it except for change the window size for the sake of the screenshot (even left good ol' cornflower blue on the background). You can see it here, running at a solid... 51 FPS. Doing nothing...

I also included my system specs in the screenshot, and I like I said, this is my main gaming machine, and while it's certainly not top-of-the-line, I have done a lot of pretty hefty gaming on it. There is NO reason that it should be running an empty game at 51 FPS.

[url="http://imgur.com/N0Woh"]http://imgur.com/N0Woh[/url]

So... Any ideas here? Should I consider the possibility that I have a virus causing this? It seems unlikely, but I did notice that MSE was wanting to scan my machine every single day for a couple weeks, which seemed unusal. If you guys have any other suggestions, I would love to hear them, because I am stumped, and basically resigning myself to just using my laptop for XNA development (which, as I mentioned, does not have any of these issues, even though it is a bit slower).

If I cannot fix it, I may just have to nuke it from orbit and re-install Windows (it's the only way to be sure), but I [i]really[/i] do not want to do that.

Again, I just want to say thanks for all the suggestions so far. Whether I get this resolved or not, I am very appreciative of all the replies. :)

Share this post


Link to post
Share on other sites
If it's happening with other games it's probably either a driver issue or a hardware issue. My first guess would be that the graphics card gets hot, and the driver then restricts performance to try to bring the temperature back down.

Share this post


Link to post
Share on other sites
[quote name='Adam_42' timestamp='1317979843' post='4870041']
If it's happening with other games it's probably either a driver issue or a hardware issue. My first guess would be that the graphics card gets hot, and the driver then restricts performance to try to bring the temperature back down.
[/quote]

What's weird, though, is that it works fine with much more demanding games. I was playing Darksiders just a couple days ago with resolution and settings maxed, and it worked just fine. Yet it chokes on an XNA game doing nothing but displaying a blue screen... It just doesn't make sense.

[quote name='Matias Goldberg' timestamp='1317995621' post='4870124']
Watch the memory consumption. How big is when running at 60fps? How big is when running at 48fps?
[/quote]

Memory is pretty much the same whether it is running properly or slowly, and even shows pretty much the same on both of the machines I have been testing on. You probably saw it above, but the CPU does ramp up to 25% on the "bad" machine when it drops the frame rate, but no unusual memory activity that I have noticed.


I don't know... I have more or less resigned myself to re-installing Windows this weekend unless someone has any other ideas that might fix it in a less... dramatic way. To be honest, it's probably time anyway, as it has been almost two years, and I have installed/un-installed a lot of junk in that time. I do not look forward to it, but I can just continue working on my laptop while I get my desktop back up to speed. If it [i]still[/i] doesn't work right after a re-install... I don't know, maybe I will buy a new video card. I just don't have the patience to keep troubleshooting such a non-sense issue like this. It is soooooo frustrating...

Anyway, thanks again for all the advice! Much appreciated! (And I am still receptive if anyone has any other suggestions besides re-installing Windows.)

Share this post


Link to post
Share on other sites
Just one last update, in case anyone is still reading. I just tried Terraria and Capsized, two games in my Steam library that I know to be made in XNA. Terraria sort of bounced back and forth between 48 and 60, but Capsized was locked steadily at 48.

I have a few more hours worth of work to do on a Flash game I am finishing, but after that I am just going to do a clean install of Windows, and hope that fixes the problem. Thank god for Ninite!

What I cannot get my head around is why the GameTime and frame rate don't agree. Game Time shows a consistent 16ms draw/update rate, even though Fraps reports 48 FPS, and you can clearly see that the game is running choppy. (Normally, I would use the time difference to smooth out the motion at slower frame rates, but I can't even do that, because the game still [i]thinks [/i]it is running at 60 FPS).

Share this post


Link to post
Share on other sites
[quote name='Matias Goldberg' timestamp='1318112745' post='4870619']
May be a timer bug due to your process bouncing in multiple cores even if it's single threaded? Try locking your app to just one CPU (preferably the first one) in your task manager.
[/quote]

Yeah, I tried that as well, and still no luck. :(

I actually did find one more person having the same issue in the GameDev section on Reddit, but we have not been able to pin down a common cause...

Also, I went through with the clean install of Windows. Right off the bat, I installed the video driver, MS Security Essentials, VS 2010, and XNA GS, and sure enough, it was still doing it with no more software/drivers than those on the system. I also got desperate and tried one-by-one disabling some of the CPU power-saving features in my PC's BIOS, and none of them fixed it. Furthermore, I even tried removing any extra hardware that could be causing conflicts, and still no luck. Basically, at this point, I am just going to have to stick to my laptop, because the issue doesn't happen there. The only other thing I can think of is to try replacing the video card, but I am not going to do that, because I just bought my current one a few months ago.

Anyway, thanks again for all your help. Sorry I couldn't come out with a happier outcome. :(

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this