FPS drop at regular intervals

So… I know this is months later, but I feel like I should post this just in-case anyone needs it.

First off, there’s a great explanation for why the stutter happens written up by willmotil here: http://community.monogame.net/t/solved-jittery-choppy-frame-movement-for-2d-game/11888/2

But second off, I found out what was causing it for my specific instance.

I had made a static DebugDraw class, and the way I had set it up was that basic 3D and 2D shapes and text could be drawn from anywhere. What I mean by that is, it didn’t matter if I called DebugDraw.DrawText(); in an Update(), a Draw(), or wherever, it would still be drawn (it’s not the most efficient way of doing things, I know, but it’s for debug use only).

Here’s the stutter causing part: the way I accomplished it was by having the DebugDraw.DrawX() calls fill up a List with the debug shapes, which were then iterated through and drawn DebugDraw.Draw(). After they had been drawn, I cleared the shape list in preparation for the next frame, but I cleared it in the Draw() step.

This was what was causing the issue. It finally hit me when I needed to draw 200+ debug shapes each frame, and my game just locked up. What was happening was, multiple Update() calls were happening before the Draw() was being reached, and my debug shape list wasn’t being cleared between them. Once I put the debug shape list clear() call inside of PreUpdate(), the stutter bug was finally fixed!

1 Like