Frame Skips / Frame Drops

I’m developing a 2D game using MonoGame. I’ve got a square on the screen I can move around. I’m using gameTime.ElapsedGameTime.TotalSeconds to calculate movement. The problem is that about once a second, the square jumps a bit. Using a frame counter I found here I’ve concluded that my FPS drops from 59.9988 to either 59.3988 or 59.6988. It’s skipping frames.

I’ve tried googling and searching forums for hours but can’t find a solution. I’ve commented out everything in the Draw method of the Game class except for the frame counter and it still happens. I even tried creating an entirely new MonoGame project with nothing in it except the frame counter and still I would get the frame skips.

Setting IsFixedTimeStep = true does not fix the issue. I do get higher frame rate, but also not as high as I would expect (not higher than ~100). I’ve looked at the diagnostic tools and there is no garbage collection going on (no yellow triangles, Visual Studio 2015).

I am completely at a loss. If anyone has any insights to offer, it would be much appreciated.

@Arnold_Ishin

Not sure why you need such a complicated looking class for a simple FPS counter. All I use in my DRAW() method is this:

var FPS = (int)Math.Ceiling(1000 / (float)gameTime.ElapsedGameTime.TotalMilliseconds);

Then draw out the value to screen. Also use milliseconds, it’s more accurate IMHO.

From my basic understanding the UPDATE() method is the one that will always get called, and if the machine is having processing issues, it will drop the occasional call to the Draw() method, that is why you might get frame drops from 60fps to say 59 or lower.

Perhaps a rounding issue during movement. Are you using a float to move and then resolve to int for drawing?

Check here for some more overview or google some more specifics and might get some good stack exchange topics.

This is an average of your FPS. So for me it is not a big problem, since the delta of 0.6 is not so big.
I have a little delta too with my game with @Harag’s method without ceil though (I only display 4 digits after the .).
But as the fact of making stats in realtime increases overhead, it’s not surprising me. If you had about 2FPS of difference, then it would be enough to worry about.
Or maybe the call to dequeue average is too slow when it reaches MAXIMUM_SAMPLES and adds some overhead. Queues are not the fastest way of doing this. This class it not either.
You should profile the app to confirm where/when it “skips”.

Thanks for the replies everybody.

From my basic understanding the UPDATE() method is the one that will always get called, and if the machine is having processing issues, it will drop the occasional call to the Draw() method, that is why you might get frame drops from 60fps to say 59 or lower.

This is exactly the issue. My problem is that I do not know what is causing it. As I said in my post, starting a completely new MonoGame project with literally nothing in it other than an FPS counter will have this problem.

Perhaps a rounding issue during movement. Are you using a float to move and then resolve to int for drawing?

I am using only floats for movement, storing position and velocity in a Vector2, then doing position += velocity * (float)gameTime.ElapsedGameTime.TotalSeconds; The amount of Updates per second is at a steady 60, so this should not be the problem.

You should profile the app to confirm where/when it “skips”.

Could you recommend a good, easy to use profiler? I have never used one before.

I have limited experience but VS 2015 (I think pro only?) is simple enough.

@AnorLondo, I get some jumping in my game too. I’m running Windows 7 64-bit on Parallels on OS X. When I switched to running Win7/Parallels in full screen mode and switched my game to full screen, the jumping went away either completely or close to it.

I still see some “shearing” but I see that in other native OS X games like Borderlands. I don’t think my video card and monitor are the best of friends. And the shearing is not the same as the jumping.

If I toggle my full screen mode on the game (it supports Ctrl+F for this) back to windowed, the jumping comes back.

So what versions of Windows, Visual Studio and MonoGame are you on? Do you run in a VM? Do you run full screen or not? Have you tried a Release build and running without the debugger?

Does it happen for you if you have one square moving around and no frame counter in full screen mode for a Release mode with no debugging?

I’m running Windows 10 Home 64 bit.

I’ve tried setting the game to fullscreen but it doesn’t make a difference. I’ve also built the game to release but again, no go. I’m not running in a VM.

Does it happen for you if you have one square moving around and no frame counter in full screen mode for a Release mode with no debugging?

Yes, it still happens unfortunately.

The profiler available in visual studio should be sufficient :wink:

I also recall that some people have had such problems resolved by changing their custom settings on graphics drivers, outside of the game they were having issues with.

So you get the jumping with just one square moving around on the screen and no frame rate counter? If you want to share that project (say via Dropbox or similar), I could run it on my VM and also a Win 8 laptop and see what results I get. I’m curious.

I observing it too.
My frames are dropping between 55-60.
It can be okay over minutes but then it suddenly starts…
Or its starts right away immediatly after the game starts.
I cant see a connection between my code and the framedrops, that happen like this.
My GC only appears once after game starts.(The Yellow triangle)

Update:
When the drops happend i started a fresh new project with nothing to draw, and fraps shows me framedrops there as well. Now i am sure, it must be something else.
Very strange…

Update Update:
Okay, frames are dropping a soon theres “nothing else to do” , i let twitch stream running and get stable 60 Fps,when i turn it off its starts again. There must be 100% a connection.

Update Update Udate:
Now i am mad, stable 60 fps even if i turned all unnessery stuff off.
I could reproduce it serval times, that there would be a connection betwenn running stream and no stream.

I don’t know if streaming to Twitch uses nvidia’s streaming feature, but it could certainly creates an overhead on the CPU load/ maybe GPU if hardware compression is used ?
When you do something else than running your game and you want max prefs, it’s not the best way to profile it… Keep only your game running without background tasks…

Thanks for the replies everyone. After a bit of closing random programs and seeing what happens, I found out that the program f.lux (even when it was before sunset) was causing the problem. Closing it makes the stuttering disappear.

1 Like

Thanks. I actually had that one in a list of “sources of frame stuttering” which I should have shared earlier. It’s taken from misc notes around the web. It currently reads:

  • Custom settings on ATI and Nvidia drivers can override game settings and cause issues with frame rate and stuttering.
  • Utilities like f.lux can cause frame rates to drop and/or stutter even outside their active time periods.
  • Background processes like PresentationFontCache.exe can consume CPU. Check Task Manager for CPU consumption.
  • Malware such as viruses or spyware can slow down a machine.
  • Open applications such as web browsers can slow down a machine.