SDL icon indicating copy to clipboard operation
SDL copied to clipboard

[SDL2/3] [Emscripten] `SDL_CreateRendererWithProperties` throws an error when setting VSync

Open tadashibashi opened this issue 8 months ago • 0 comments

In both SDL2 and 3, Emscripten builds will throw a browser error (more like a warning) that it does not allow you to set VSync until emscripten_set_main_loop has been set.

This might be a quick hack, but using the preprocessor to strip out the call to SDL_SetRenderVSync in SDL_CreateRendererWithProperties in SDL_render.c in the main branch seems to solve this:

#ifndef __EMSCRIPTEN__
    int vsync = (int)SDL_GetNumberProperty(props, SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_NUMBER, 0);
    if (SDL_SetRenderVSync(renderer, vsync) < 0) {
        if (vsync == 0) {
            // Some renderers require vsync enabled
            SDL_SetRenderVSync(renderer, 1);
        }
    }
#endif

When the user manually calls emscripten_set_main_loop, the second parameter is where vsync is specified, by passing -1.

This issue in emscripten's repo also mentions this, for reference.

tadashibashi avatar Jun 04 '24 19:06 tadashibashi