Fixed SDL_RenderSetVSync does not update flags if simulated vsync is on

This lets the user to correctly detect current vsync state by reading SDL_RendererInfo.
Also fixes SetVSync's return value check (it may be positive for error too).

(cherry picked from commit d78072fcd4)
This commit is contained in:
Ivan Mogilko 2023-03-18 00:39:02 +03:00 committed by Sam Lantinga
parent 08d5c1386e
commit f360965db6
1 changed files with 6 additions and 1 deletions

View File

@ -4306,8 +4306,13 @@ int SDL_SetRenderVSync(SDL_Renderer *renderer, int vsync)
} }
if (!renderer->SetVSync || if (!renderer->SetVSync ||
renderer->SetVSync(renderer, vsync) < 0) { renderer->SetVSync(renderer, vsync) != 0) {
renderer->simulate_vsync = vsync ? SDL_TRUE : SDL_FALSE; renderer->simulate_vsync = vsync ? SDL_TRUE : SDL_FALSE;
if (renderer->simulate_vsync) {
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
} else {
renderer->info.flags &= ~SDL_RENDERER_PRESENTVSYNC;
}
} else { } else {
renderer->simulate_vsync = SDL_FALSE; renderer->simulate_vsync = SDL_FALSE;
} }