From e13a30f00fc77e0182db9968ede9574d15029da8 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Mon, 18 Mar 2024 10:20:29 +0000 Subject: [PATCH] effects: Do not take ownership of QuickEffect::delegate QuickEffect::setDelegate is exposed QML API. The lifespan of assigned objects is therefore managed by the QML engine, and we should be watching for deletion not actually deleting it. --- src/effect/quickeffect.cpp | 11 ++++++----- src/plugins/overview/overvieweffect.cpp | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/effect/quickeffect.cpp b/src/effect/quickeffect.cpp index 4fa0ab023b..e8a6061c4b 100644 --- a/src/effect/quickeffect.cpp +++ b/src/effect/quickeffect.cpp @@ -65,7 +65,7 @@ public: } bool isItemOnScreen(QQuickItem *item, Output *screen) const; - std::unique_ptr delegate; + QPointer delegate; QUrl source; std::map> contexts; std::map> incubators; @@ -248,7 +248,7 @@ void QuickSceneEffect::setSource(const QUrl &url) } if (d->source != url) { d->source = url; - d->delegate.reset(); + d->delegate.clear(); } } @@ -265,7 +265,7 @@ void QuickSceneEffect::setDelegate(QQmlComponent *delegate) } if (d->delegate.get() != delegate) { d->source = QUrl(); - d->delegate.reset(delegate); + d->delegate = delegate; Q_EMIT delegateChanged(); } } @@ -472,11 +472,12 @@ void QuickSceneEffect::startInternal() return; } - d->delegate = std::make_unique(effects->qmlEngine()); + d->delegate = new QQmlComponent(effects->qmlEngine(), this); d->delegate->loadUrl(d->source); + if (d->delegate->isError()) { qWarning().nospace() << "Failed to load " << d->source << ": " << d->delegate->errors(); - d->delegate.reset(); + d->delegate.clear(); return; } Q_EMIT delegateChanged(); diff --git a/src/plugins/overview/overvieweffect.cpp b/src/plugins/overview/overvieweffect.cpp index 58ccb04ec0..bb71edac27 100644 --- a/src/plugins/overview/overvieweffect.cpp +++ b/src/plugins/overview/overvieweffect.cpp @@ -158,7 +158,7 @@ OverviewEffect::OverviewEffect() OverviewConfig::instance(effects->config()); reconfigure(ReconfigureAll); - auto delegate = new QQmlComponent(effects->qmlEngine()); + auto delegate = new QQmlComponent(effects->qmlEngine(), this); connect(delegate, &QQmlComponent::statusChanged, this, [delegate]() { if (delegate->isError()) { qWarning() << "Failed to load overview:" << delegate->errorString();