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.
cc @Daft-Freak @juj @kripken
Emscripten allows customizing the canvas element used for graphics via the
Module.canvasproperty.However, in SDL the canvas ID is currently hardcoded:
SDL/src/video/emscripten/SDL_emscriptenvideo.c
Line 204 in 71e06a5
This results in undecipherable errors during start-up when

#canvaselement does not exist on the page:Looking further through Emscripten docs, I see that
#canvasused 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=0works around the issue and draws to the canvas set inModule.canvasinstead of trying to find#canvaselement 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.canvasor viaemscripten_webgl_make_context_current.cc @Daft-Freak @juj @kripken