Skip to content

Allow customizing canvas on Emscripten #5260

Description

@RReverser

Emscripten allows customizing the canvas element used for graphics via the Module.canvas property.

However, in SDL the canvas ID is currently hardcoded:

wdata->canvas_id = SDL_strdup("#canvas");

This results in undecipherable errors during start-up when #canvas element does not exist on the page:
image

Looking further through Emscripten docs, I see that #canvas used to mean "whatever element is currently set as the default canvas" in the past, and I'm guessing SDL's hardcoded string was added before that behaviour has changed:

image

Indeed, compiling with -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=0 works around the issue and draws to the canvas set in Module.canvas instead of trying to find #canvas element on the page.

However, this is just a workaround and, I believe SDL should support the non-deprecated behaviour and respect canvas customizations set in Module.canvas or via emscripten_webgl_make_context_current.

cc @Daft-Freak @juj @kripken

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions