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 <lorn.potter@gmail.com>
This commit is contained in:
Morten Johan Sørvig 2019-11-08 02:19:02 +01:00
parent c625d92385
commit 4d796cbf17

View File

@ -30,6 +30,7 @@
#include "qwasmopenglcontext.h"
#include "qwasmintegration.h"
#include <EGL/egl.h>
#include <emscripten/val.h>
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;
}
}