From 208964f038210c6076a6916315420b05ff9435a0 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 15 Sep 2022 07:05:55 -0700 Subject: [PATCH] Reset the simulated vsync presentation timeline if it's been too long since the last present --- src/render/SDL_render.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c index c0b0032b1..aa6bd402f 100644 --- a/src/render/SDL_render.c +++ b/src/render/SDL_render.c @@ -4288,11 +4288,12 @@ SDL_RenderSimulateVSync(SDL_Renderer * renderer) now = SDL_GetTicks(); } - if (renderer->last_present) { - elapsed = (now - renderer->last_present); - renderer->last_present += (elapsed / interval) * interval; - } else { + elapsed = (now - renderer->last_present); + if (!renderer->last_present || elapsed > 1000) { + /* It's been too long, reset the presentation timeline */ 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->last_present = 0; if (!renderer->SetVSync || renderer->SetVSync(renderer, vsync) < 0) {