From adac3b8646cc3de8e5d5e515f11038469395b67d Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 13 Jul 2021 12:33:07 +0300 Subject: [PATCH] scripting: Guard against the case where a window is destroyed after changing visibility If the visiblityChanged signal is emitted and then the window is immediately destroyed, the slot will still be executed because the connection has type of Qt::QueuedConnection. --- src/scripting/scripting.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/scripting/scripting.cpp b/src/scripting/scripting.cpp index 27e842bdc0..6870121c9c 100644 --- a/src/scripting/scripting.cpp +++ b/src/scripting/scripting.cpp @@ -570,9 +570,10 @@ QVariant KWin::JSEngineGlobalMethodsWrapper::readConfig(const QString &key, QVar void KWin::JSEngineGlobalMethodsWrapper::registerWindow(QQuickWindow *window) { - connect(window, &QWindow::visibilityChanged, this, [window](QWindow::Visibility visibility) { - if (visibility == QWindow::Hidden) { - window->destroy(); + QPointer guard = window; + connect(window, &QWindow::visibilityChanged, this, [guard](QWindow::Visibility visibility) { + if (guard && visibility == QWindow::Hidden) { + guard->destroy(); } }, Qt::QueuedConnection); }