FPS problem with near no code on Windows 8.1

I have created a generic project for Windows.

I simply changed the following…

public static string FPSCount = string.Empty;
public static string LowestFPSCount = string.Empty;
private float fpsLowestCount = 99999;

    public Game1()
        : base()
        Window.IsBorderless = true;
        graphics = new GraphicsDeviceManager(this);
        graphics.PreferredBackBufferWidth = 1024;
        graphics.PreferredBackBufferHeight = 768;
        graphics.SynchronizeWithVerticalRetrace = false;

        // //graphics.IsFullScreen = true;
        this.IsFixedTimeStep = true;
        TargetElapsedTime = TimeSpan.FromSeconds(1.0f / 999);
        Content.RootDirectory = "Content";


and …

 protected override void Draw(GameTime gameTime)

        Game1.FPSCount = (1 / (float)gameTime.ElapsedGameTime.TotalSeconds).ToString();
        if ((1 / (float)gameTime.ElapsedGameTime.TotalSeconds) < fpsLowestCount && gameTime.TotalGameTime.Seconds > 5)
            fpsLowestCount = (1 / (float)gameTime.ElapsedGameTime.TotalSeconds);
            //delegateConsole.BeginInvoke("FPS - " + FPSCount + "  Lowest - " + fpsLowestCount, null, null);
        LowestFPSCount = fpsLowestCount.ToString();


I put a conditional break point on any line in the draw function and set it to break if fps goes below 20. After running it for a few seconds to a minute the fps will go below 20.

Any idea why? I have an Alienware laptop which is not going to have any possibility of it being hardware that cannot take the base application.

This is on the latest build not the release build. I hope it is something dumb…

Thanks, in advance

‘gameTime.TotalGameTime.Seconds > 5’ must be ‘gameTime.TotalGameTime.TotalSeconds > 5’ , right?

Time it a couple of times, or simply read the ‘gameTime.TotalGameTime.TotalSeconds’ when you hit that breakpoint and write down the results. Is the time that this happends consisted?
Now remove all .ToString() calls. time it again a few times and write down the result. Any change ?

Probably the .ToString() method generates garbage and your laptop is not strong enough to handle a GC within 16ms. GC is tringered every 1MByte allocated memory. If for example this happend every 60 seconds @ 60fps, you are generating 1MB/(60s*60f/s) = 1MB/3600f = 291 bytes / frame.

Use profiler to see what is really going on with the code.

Since you are setting IsFixedTimeStep = true; then gameTime.ElapsedGameTime.TotalSeconds must always be 0.016s. MG just skip Draw() when needed and your frame counting is wrong. …or am i missing something here?

simplified down to this…

public Game1()
        : base()
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";


 protected override void Draw(GameTime gameTime)
        currentfps = (1 / (float)gameTime.ElapsedGameTime.TotalSeconds);

        if(gameTime.TotalGameTime.Seconds > 5)
            int i = 0;  //I put conditional break point here


seems like different amount of seconds this drop to below 20 fps happens and will be anywhere as low as 2. My machine is not that weak. This is not drawing anything, I have to be missing something. I removed our entire Game logic from this solution because it was happening to our game, so very complicated software is dropping fps like this, and a project with nothing in it is doing the same.

Can you please give some more info…
which version of MonoGame? Have you used the latest developer build?

is this a Metro app win8.1 or desktop? which template? I can’t find a templete for desktop.
32bit windows or x64?
VS 2013?
If you could share the project on dropbox/oneDrive it could be nice.
There are a few things you can try yourself, like runing the profiler or mesure the frame rate with other methods, like Fraps for example.

Edit: ok, i found the template, it’s only for VS2010. DX or OpenGL?

ok, fraps report a steady 60fps for both DX & GL.
putting a breakpoint on line int i=0; gives me currentfps = 59.9999.
Of course if press F5 the second time it gives me currentfps = 2.06…
you have to let it run a few sec to catch up.

I suggest to run a profiler on your full game to see what’s really going on.

I put a conditional breakpoint for if the fps drops below 30 or 5 or something. I wait for 5 seconds which is what the if statement is so I do not just get the low fps of boot of the app.

It is DX and it is with the latest build. The problem is not average fps, it is the fact that it will drop to 2 fps then go back to normal 99% of the time. But the sudden lack of a draw call being made chugs any user experience especially when it goes down into the single digits. Here is the simple project on dropbox.

Profiler told me basically this project does nothing at all. which is true. but my question is why is gametime going so badly then? With the basic project created out of the box, gametime should remain constant in the draw as it is by default locked to 60 fps right? if the basic do nothing app drops below 60 fps, this is not usable.

It never drop below 60fps. The code you have to mesure fps is wrong.

currentfps is always = 59.9999 because IsFixedTimeStep is =true by default. Even if there are frame drops you will never see that within Draw() because ElapsedTime is always 16ms (fixed time). The only way to get values like 2fps is if you have your breakpoint set while you start/resume execution, the GameTime didn’t recover yet from the long pause cause by the debugger. Also the condition make no sense, TotalGameTime.Seconds goes up to 59 and then reset back to 0. It’s true (55/60)= 91% of the time.

-Adopt a third-party/tested way to mesure FPS.
-Run the profiler on your actual game to see why you get frame drops and where you need to optimize. Also pay attention to GCs, run a memory profiler to detect garbage in case you get frame drops on constant intervals.

Read the following posts

Well dang, I think you got this!! FPS is really missleading as it is not frames drawn per second that is being limited it is updates per second that is and draw is called whenever Mono/xna sees fit. If I understand this correctly I should be able to just rearrange some logic and get things running well again. Thanks for the journey with me!!!

Game.IsFixedTimeStep relates to UPDATE!!! not DRAW!!! :smile:

1 Like

Thank magicrat,
Hope you have a nice journey forward with gameDev.