-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
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:

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:
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.
