summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/wasm/qwasmopenglcontext.cpp
diff options
context:
space:
mode:
authorMikolaj Boc <mikolaj.boc@qt.io>2022-10-20 14:05:58 +0200
committerMikolaj Boc <mikolaj.boc@qt.io>2022-10-21 18:02:34 +0200
commit2c8cf8eb42749f6999cc10169c188f9df23738f5 (patch)
tree4250e84452e10050b815d9dcfb30ce5d7f344ce6 /src/plugins/platforms/wasm/qwasmopenglcontext.cpp
parente487b07e18f1cb7ff126744be57b2ae1b9839c6c (diff)
Fix the workaround in ~QWasmOpenGLContext
The workaround stopped working because JSEvents is now not a global object. Update the workaround by exporting the JSEvents object from emscripten runtime and replacing the function that removes the event handlers to a dummy function that does nothing temporarily, only to revert it when the context is destroyed. Fixes: QTBUG-107197 Pick-to: 6.4 Change-Id: Icceae884c85e04fdafcca6cf3c563094d3f6f0dc Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'src/plugins/platforms/wasm/qwasmopenglcontext.cpp')
-rw-r--r--src/plugins/platforms/wasm/qwasmopenglcontext.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/plugins/platforms/wasm/qwasmopenglcontext.cpp b/src/plugins/platforms/wasm/qwasmopenglcontext.cpp
index da9219bd6e7..df72397211c 100644
--- a/src/plugins/platforms/wasm/qwasmopenglcontext.cpp
+++ b/src/plugins/platforms/wasm/qwasmopenglcontext.cpp
@@ -4,8 +4,18 @@
#include "qwasmopenglcontext.h"
#include "qwasmintegration.h"
#include <EGL/egl.h>
+#include <emscripten/bind.h>
#include <emscripten/val.h>
+namespace {
+void qtDoNothing(emscripten::val) { }
+} // namespace
+
+EMSCRIPTEN_BINDINGS(qwasmopenglcontext)
+{
+ function("qtDoNothing", &qtDoNothing);
+}
+
QT_BEGIN_NAMESPACE
QWasmOpenGLContext::QWasmOpenGLContext(const QSurfaceFormat &format)
@@ -26,12 +36,14 @@ 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());
+ // which removes all event handlers on the canvas by temporarily replacing the function
+ // that does the removal with a function that does nothing.
+ emscripten::val jsEvents = emscripten::val::module_property("JSEvents");
+ emscripten::val savedRemoveAllHandlersOnTargetFunction =
+ jsEvents["removeAllHandlersOnTarget"];
+ jsEvents.set("removeAllHandlersOnTarget", emscripten::val::module_property("qtDoNothing"));
emscripten_webgl_destroy_context(m_context);
- emscripten::val::global("window").set("JSEvents", jsEvents);
+ jsEvents.set("removeAllHandlersOnTarget", savedRemoveAllHandlersOnTargetFunction);
m_context = 0;
}
}