From 4d796cbf17da28e72ad25760a2ee8c27af96c202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Fri, 8 Nov 2019 02:19:02 +0100 Subject: Prevent emscripten_webgl_destroy_context from removing event handlers The JavaScript implementation of that function has the following code: if (typeof JSEvents === 'object') JSEvents.removeAllHandlersOnTarget(GL.contexts[contextHandle].GLctx.canvas); // Release all // JS event handlers on the DOM element that the GL context is associated with since the context // is now deleted. This breaks mouse/keyboard events, etc. Disable this logic by temporarily setting the JSEvents object to undefined, for the duration of the emscripten_webgl_destroy_context call. Fixes: QTBUG-74850 Change-Id: Ied3177b0ca6e63e8ea07143bf7d6a850b0bce35a Reviewed-by: Lorn Potter --- src/plugins/platforms/wasm/qwasmopenglcontext.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/plugins/platforms/wasm') diff --git a/src/plugins/platforms/wasm/qwasmopenglcontext.cpp b/src/plugins/platforms/wasm/qwasmopenglcontext.cpp index 62087f54bd..0532b7e726 100644 --- a/src/plugins/platforms/wasm/qwasmopenglcontext.cpp +++ b/src/plugins/platforms/wasm/qwasmopenglcontext.cpp @@ -30,6 +30,7 @@ #include "qwasmopenglcontext.h" #include "qwasmintegration.h" #include +#include QT_BEGIN_NAMESPACE @@ -50,7 +51,13 @@ QWasmOpenGLContext::QWasmOpenGLContext(const QSurfaceFormat &format) QWasmOpenGLContext::~QWasmOpenGLContext() { if (m_context) { + // Destroy GL context. Work around bug in emscripten_webgl_destroy_context + // which removes all event handlers on the canvas by temporarily removing + // emscripten's JSEvents global object. + emscripten::val jsEvents = emscripten::val::global("window")["JSEvents"]; + emscripten::val::global("window").set("JSEvents", emscripten::val::undefined()); emscripten_webgl_destroy_context(m_context); + emscripten::val::global("window").set("JSEvents", jsEvents); m_context = 0; } } -- cgit v1.2.3