Why does MonoGame calls DoUpdate() before RunLoop()?

I am reading the source code to learn how MonoGame works internally, and in the Run(GameRunBehavior) method of the Game class I noticed the following:

 case GameRunBehavior.Synchronous:
                    // XNA runs one Update even before showing the window
                    DoUpdate( new GameTime() );

                    Platform.RunLoop();
                    EndRun();
                    DoExiting();
                    break;

There’s DoUpdate()

Later on, inside the Platform.RunLoop() it calls Game.Tick(), which then calls internally DoUpdate() again

From what I understand, it gets on an endless game loop on Platform.RunLoop() until the user quits the game.

But why is it required to run that isolated DoUpdate() before it gets on the loop?

The comment in the code says it all. One of the goals of MonoGame is to be a drop-in replacement for XNA. XNA calls update once before starting the run loop.

Basically it’s insurance in case of some, edge case / lazy initialization or some weird thing occurs, its fairly common if you write your own render loop to see people do it…

You always want to make sure update runs before draw at game start twice is even better. Most of the time its not even requisite, sometimes in rare cases it can be the difference between a divide by zero in draw on a timer or such.

1 Like

Thanks @willmotil, that clears things up :slight_smile: