From ecf0cc36936f69830a07937b97807ec0ba4d3f41 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Mon, 10 Jan 2022 09:22:09 +0000 Subject: [PATCH] Don't crash when a screen gets disabled and enabled again when a screen gets disabled, the containment loses its view, and when gets enabled again, the process of the old orphaned containment getting a new view causes a plasma crash. It comes from the wallpaper, which indicates a hierarchy of C++ owned objects makes the internal one (wallpaper) to not reset correctly its window and have a stray pointer to it. BUG:447752 --- .../qml/plasmoid/containmentinterface.cpp | 21 +++++++++++++++---- .../qml/plasmoid/containmentinterface.h | 1 + 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.cpp b/src/scriptengines/qml/plasmoid/containmentinterface.cpp index d8a89014c..29a7738ca 100644 --- a/src/scriptengines/qml/plasmoid/containmentinterface.cpp +++ b/src/scriptengines/qml/plasmoid/containmentinterface.cpp @@ -74,10 +74,6 @@ void ContainmentInterface::init() connect(m_activityInfo, &KActivities::Info::nameChanged, this, &ContainmentInterface::activityNameChanged); Q_EMIT activityNameChanged(); - if (!m_containment->wallpaper().isEmpty()) { - loadWallpaper(); - } - AppletInterface::init(); // Create the ToolBox @@ -1162,4 +1158,21 @@ bool ContainmentInterface::isLoading() const return loading; } +void ContainmentInterface::itemChange(ItemChange change, const ItemChangeData &value) +{ + if (change == QQuickItem::ItemSceneChange) { + // we have a window: create the representations if needed + if (value.window && !m_containment->wallpaper().isEmpty()) { + loadWallpaper(); + } else if (m_wallpaperInterface) { + m_wallpaperInterface->deleteLater(); + m_wallpaperInterface = nullptr; + Q_EMIT wallpaperInterfaceChanged(); + } + } + + AppletInterface::itemChange(change, value); +} + + #include "moc_containmentinterface.cpp" diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.h b/src/scriptengines/qml/plasmoid/containmentinterface.h index a91c60c5e..f1276ee80 100644 --- a/src/scriptengines/qml/plasmoid/containmentinterface.h +++ b/src/scriptengines/qml/plasmoid/containmentinterface.h @@ -169,6 +169,7 @@ protected: void addContainmentActions(QMenu *desktopMenu, QEvent *event); virtual bool isLoading() const override; + void itemChange(ItemChange change, const ItemChangeData &value) override; Q_SIGNALS: /** -- GitLab