Unexpected little freeze

Hello,
I work on a game with rider (https://www.jetbrains.com/rider/) with an almost empty monogame project. In fact i only have one sprite wich is moving across the screen but the movements is not smooth at all. I profile my game and i saw that 70% of the process time is in the Thread.Sleep() method of monogame.
So why monogame prefer to sleep instead of run my game more smoothly ?

Here the profiler:


Have you turn V-sync off?

MonoGame runs at a fixed time step of 60 fps by default. It sleeps if it has time left over until the next frame. Set Game.IsFixedTimeStep and GraphicsDeviceManager.SynchronizeWithVerticalRetrace to false to unlock frame rate.

Ok i’ve done it and now I have Game.DoDraw() which is 70%, that’s what we expected ? :upside_down:

You probably had FixedTimeStep=true and VSync=false.
In than case MG MG uses Sleep() which is indeed unstable. Sometimes it sleeps more than what’s needed and you skip a frame.

With FixedTimeStep=true and VSync=true the frames are mostly synced by the GPU.
With FixedTimeStep=false and VSync=false you are drawing as many frames as possible without sleeping. you still seeing what your monitor can draw but it’s useful for benchmarking.

1 Like

Ok nice ! I undestand better now and those freeze dont come from Monogame but from my old monitor :flushed:
So with a more recent display it worked very well and smoothly :sweat_smile:
Any way i did not lose my time it was instructive :innocent:

Thanks all

1 Like

That’s not what I said. :neutral_face:

But that’s what i saw :innocent:
The game was ten times smoother on my other screen