From 83106badcdeab65254bf15a338ea10db91785f3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rvig?= Date: Fri, 6 May 2022 11:41:36 +0200 Subject: [PATCH] wasm: always call destroy() before deleting a screen QWasmCompositor currently has the requirement that destroying it requires freeing a GL texture, which requires a valid GL context, which requires a valid screen, in order to get to the native context on the canvas. For this reason QWasmScreen has a destroy() function which is called before deleting the QScreen and QPlatformScreen. Make sure we call destroy() also when deleting all screens in the QWasmIntegration destructor. Move the common logic into a new deleteScreen() function which replaces destroy(). Change-Id: I628f13c868808db539effff9b29ecbefac23abc9 Reviewed-by: Aleksandr Reviakin Reviewed-by: Lorn Potter Reviewed-by: David Skoland --- src/plugins/platforms/wasm/qwasmintegration.cpp | 8 +++----- src/plugins/platforms/wasm/qwasmscreen.cpp | 3 ++- src/plugins/platforms/wasm/qwasmscreen.h | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp index c6bb7f98c9..b7e1a0ad28 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.cpp +++ b/src/plugins/platforms/wasm/qwasmintegration.cpp @@ -196,7 +196,8 @@ QWasmIntegration::~QWasmIntegration() delete m_drag; for (const auto &elementAndScreen : m_screens) - QWindowSystemInterface::handleScreenRemoved(elementAndScreen.second); + elementAndScreen.second->deleteScreen(); + m_screens.clear(); s_instance = nullptr; @@ -338,10 +339,7 @@ void QWasmIntegration::removeScreen(const emscripten::val &element) qWarning() << "Attempting to remove non-existing screen for element" << QWasmString::toQString(element["id"]);; return; } - QWasmScreen *exScreen = it->second; - m_screens.erase(it); - exScreen->destroy(); // clean up before deleting the screen - QWindowSystemInterface::handleScreenRemoved(exScreen); + it->second->deleteScreen(); } void QWasmIntegration::resizeScreen(const emscripten::val &element) diff --git a/src/plugins/platforms/wasm/qwasmscreen.cpp b/src/plugins/platforms/wasm/qwasmscreen.cpp index 357ee327fe..03c672b9ba 100644 --- a/src/plugins/platforms/wasm/qwasmscreen.cpp +++ b/src/plugins/platforms/wasm/qwasmscreen.cpp @@ -131,9 +131,10 @@ QWasmScreen::~QWasmScreen() m_canvas.set(m_canvasResizeObserverCallbackContextPropertyName, emscripten::val(intptr_t(0))); } -void QWasmScreen::destroy() +void QWasmScreen::deleteScreen() { m_compositor->destroy(); + QWindowSystemInterface::handleScreenRemoved(this); } QWasmScreen *QWasmScreen::get(QPlatformScreen *screen) diff --git a/src/plugins/platforms/wasm/qwasmscreen.h b/src/plugins/platforms/wasm/qwasmscreen.h index 07f52f9fdc..65efefdeef 100644 --- a/src/plugins/platforms/wasm/qwasmscreen.h +++ b/src/plugins/platforms/wasm/qwasmscreen.h @@ -55,7 +55,7 @@ class QWasmScreen : public QObject, public QPlatformScreen public: QWasmScreen(const emscripten::val &containerOrCanvas); ~QWasmScreen(); - void destroy(); + void deleteScreen(); static QWasmScreen *get(QPlatformScreen *screen); static QWasmScreen *get(QScreen *screen);