High frame 1 dt when Vsync and framecap are disabled?

When Vsync and framecap are both disabled, the very first dt value is abnormally high. In the attached example my console reads numbers around 0.34 when both Vsync and framecap are disabled. If either are enabled, the value matches the framerate - as expected. What is going on here to cause the crazy high dt?

High Frame 1 DT.zip (14.7 KB)

3 Likes

I cannot say for sure what’s causing this.
My guess is that something in the engine initializes during the first update, causing that frame to take more time than desired.
I won’t know more without debugging I’m afraid.

A small precaution, since I noticed that you are creating a global value (the “switch” variable), and that will be shared between all the scripts, which might not always be what you want.

1 Like

But then why is it not the case when Vsync or framecap are enabled? It has no problem initializing frame 1 in 0.016 dt when Vsync is on, but for some reason needs 0.34 dt worth of resources to do the same when it is off?

2 Likes

Good question!
And after further inspection, it was the “previous frame time” that was initialized a bit early in the dmEngine::Init() function. That code was now moved to the end of that function.
However, moving that code closer to the next dmEngine::Step() resulted in a extremely low dt instead (0.000004 s). That too seems a bit unusable as a good dt.
So, for the first frame we guess at a framerate of 60fps (since we don’t know how long the frames will take).

A Pull Request for issue #5644 is ready, and it will be in the 1.2.181 release.

Good catch @rocamocha! Thanks!

7 Likes