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.
This commit is contained in:
Vlad Zahorodnii 2021-07-13 12:33:07 +03:00
parent 23129c09ce
commit adac3b8646

View file

@ -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<QQuickWindow> guard = window;
connect(window, &QWindow::visibilityChanged, this, [guard](QWindow::Visibility visibility) {
if (guard && visibility == QWindow::Hidden) {
guard->destroy();
}
}, Qt::QueuedConnection);
}