From f88666eb4798123f6cde17a2eb49cd0b78384951 Mon Sep 17 00:00:00 2001 From: James Zern Date: Fri, 29 Mar 2024 11:53:13 -0700 Subject: [PATCH] webp_js/*.html: fix canvas mapping after: 24d7f9cb Switch code to SDL2. fixes: webp_wasm.js:1 Uncaught TypeError: Cannot read properties of null (reading 'addEventListener') at Object.registerOrRemoveHandler (webp_wasm.js:1:101330) at registerMouseEventCallback (webp_wasm.js:1:154227) at _emscripten_set_mousemove_callback_on_thread (webp_wasm.js:1:155015) ... The SDL2 port forces the canvas id to '#canvas': https://github.com/emscripten-ports/SDL2/blob/324df6865ae3c7d194ed233a86867c48ec96c6a3/src/video/emscripten/SDL_emscriptenvideo.c#L210 This change maps '#output_canvas' to this entry in specialHTMLTargets[]: https://emscripten.org/docs/api_reference/html5.h.html https://github.com/libsdl-org/SDL/issues/5260 & https://github.com/emscripten-ports/SDL2/issues/130 may also be related. Change-Id: I26f4aa22b9d68b0fc45b83edfe6fe074b59a82a7 Test: emscripten 3.1.16 --- webp_js/index.html | 2 ++ webp_js/index_wasm.html | 2 ++ 2 files changed, 4 insertions(+) diff --git a/webp_js/index.html b/webp_js/index.html index 33cacb4c..e7c3b652 100644 --- a/webp_js/index.html +++ b/webp_js/index.html @@ -29,6 +29,8 @@ function decode(webp_data, canvas_id) { // clear previous picture (if any) Module.canvas = canvas; canvas.getContext('2d').clearRect(0, 0, canvas.width, canvas.height); + // Map this canvas to the default selector used by emscripten/SDL2. + specialHTMLTargets["#canvas"] = Module.canvas; // decode and measure timing var start = new Date(); var ret = WebpToCanvas(webp_data, webp_data.length); diff --git a/webp_js/index_wasm.html b/webp_js/index_wasm.html index 7a9b362a..29933aba 100644 --- a/webp_js/index_wasm.html +++ b/webp_js/index_wasm.html @@ -30,6 +30,8 @@ function decode(webp_data, canvas_id) { // clear previous picture (if any) Module.canvas = canvas; canvas.getContext('2d').clearRect(0, 0, canvas.width, canvas.height); + // Map this canvas to the default selector used by emscripten/SDL2. + specialHTMLTargets["#canvas"] = Module.canvas; // decode and measure timing var start = new Date(); var ret = WebpToCanvas(webp_data, webp_data.length);