Reset the simulated vsync presentation timeline if it's been too long since the last present

This commit is contained in:
Sam Lantinga 2022-09-15 07:05:55 -07:00
parent 1663cb4196
commit 208964f038
1 changed files with 5 additions and 5 deletions

View File

@ -4288,11 +4288,12 @@ SDL_RenderSimulateVSync(SDL_Renderer * renderer)
now = SDL_GetTicks(); now = SDL_GetTicks();
} }
if (renderer->last_present) { elapsed = (now - renderer->last_present);
elapsed = (now - renderer->last_present); if (!renderer->last_present || elapsed > 1000) {
renderer->last_present += (elapsed / interval) * interval; /* It's been too long, reset the presentation timeline */
} else {
renderer->last_present = now; renderer->last_present = now;
} else {
renderer->last_present += (elapsed / interval) * interval;
} }
} }
@ -4575,7 +4576,6 @@ SDL_RenderSetVSync(SDL_Renderer * renderer, int vsync)
} }
renderer->wanted_vsync = vsync ? SDL_TRUE : SDL_FALSE; renderer->wanted_vsync = vsync ? SDL_TRUE : SDL_FALSE;
renderer->last_present = 0;
if (!renderer->SetVSync || if (!renderer->SetVSync ||
renderer->SetVSync(renderer, vsync) < 0) { renderer->SetVSync(renderer, vsync) < 0) {