Skip to content

emscripten: Avoid unnecessarily enabling simulate_vsync - #16151

Closed
neonmoe wants to merge 1 commit into
libsdl-org:mainfrom
neonmoe:emscripten-fix-unnecessarily-simulated-vsync
Closed

emscripten: Avoid unnecessarily enabling simulate_vsync#16151
neonmoe wants to merge 1 commit into
libsdl-org:mainfrom
neonmoe:emscripten-fix-unnecessarily-simulated-vsync

Conversation

@neonmoe

@neonmoe neonmoe commented Aug 14, 2026

Copy link
Copy Markdown
  • I confirm that I am the author of this code and release it to the SDL project under the Zlib license. This contribution does not contain code from other sources, including code generated by a Large Language Model ("AI").

Description

SDL_SetRendererVSync enables simulate_vsync if it notices that setting the swap interval does nothing: set 1, get 0 => simulate vsync. In the emscripten implementation's case, if called early enough, the setter will not actually change the emscripten main loop timing. Instead, the requested interval will be stored to be used later. The problem is, the getter gets its swap interval from the emscripten main loop's current state, which wasn't changed, and this leads to simulate_vsync being enabled.

I verified with the Chromium profiler that the original issue (unnecessary sleep) reproduces in the testrendercopyex test if vsync is enabled, and also that this PR fixes the issue (no more unnecessary sleep).

The actual fix is a little annoying, repeating the file-local pending variable pattern from SDL_emscriptenvideo.c. But it doesn't seem too ugly to me, and doesn't require communicating that state more explicitly between these two, which is a plus. I'm assuming that deferring setting the main loop timing is load-bearing enough that we should still maintain this functionality where the swap interval sometimes gets "pendingly set" instead of actually making the change.

Existing Issue(s)

This fixes #16146.

SDL_SetRendererVSync enables simulate_vsync if it notices that
setting the swap interval does nothing: set 1, get 0 => simulate
vsync. In the emscripten implementation's case, if called early
enough, the setter will not actually change the emscripten main loop
timing, instead the requested interval will be stored to be used
later. The problem is, the getter gets its swap interval from the
emscripten main loop's current state, which wasn't changed, which
leads to simulate_vsync being enabled.

This fixes libsdl-org#16146.
@slouken
slouken requested a review from icculus August 22, 2026 15:41
@slouken slouken added this to the 3.4.16 milestone Aug 22, 2026
@icculus icculus closed this in 618890f Aug 27, 2026
@icculus

icculus commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

I ended up going with a simpler approach, but this should be resolved by 618890f, now.

icculus added a commit that referenced this pull request Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SDL_HINT_RENDER_VSYNC=1 results in half of the expected refresh rate on emscripten/web

3 participants