Commit 446e23af authored by David Edmundson's avatar David Edmundson
Browse files

[aurorae] Fix crash on KCM teardown with Qt5.14

Context behaviour subtly changed in Qt5.14 which has exposed some
questionable things in this KCM.

Auorae::Decoration is a context property of the loaded QML.

QObject::~QObject signals it's own deletion before deleting children.
This means the bindings of loaded QML update in particular

   DecorationOptions {
        id: options
        deco: decoration

DecorationOptions has a pointer to the previously set decoration which
is now dangling, and we crash.

Rather than adding more guards and smart pointers in DecorationOptions,
this patch deletes the QQmlContext before deleting the context
properties that we expose.

It also moves unreferring the shared qmlcontext we inherit from till
after we've deleted the child context, because it didn't make sense.

Test Plan:
Opened KCM
Closed the KCM
didn't crash

Reviewers: #kwin, zzag

Reviewed By: #kwin, zzag

Subscribers: kwin

Tags: #kwin

Differential Revision:
parent 82f4e03d
......@@ -266,17 +266,19 @@ Decoration::Decoration(QObject *parent, const QVariantList &args)
if (m_context) {
delete m_renderControl;
delete m_item;
// deleted explicitly before our own qobject destructor as "this" is a context property of m_qmlContext,
// and changing contextProperties is a bad idea
delete m_qmlContext;
void Decoration::init()
......@@ -285,9 +287,9 @@ void Decoration::init()
auto s = settings();
connect(, &KDecoration2::DecorationSettings::reconfigured, this, &Decoration::configChanged);
QQmlContext *context = new QQmlContext(Helper::instance().rootContext(), this);
context->setContextProperty(QStringLiteral("decoration"), this);
m_qmlContext = new QQmlContext(Helper::instance().rootContext(), this);
m_qmlContext->setContextProperty(QStringLiteral("decoration"), this);
auto component = Helper::instance().component(m_themeName);
if (!component) {
......@@ -310,9 +312,9 @@ void Decoration::init()
connect(this, &Decoration::configChanged, theme, readButtonSize);
// m_theme->setTabDragMimeType(tabDragMimeType());
context->setContextProperty(QStringLiteral("auroraeTheme"), theme);
m_qmlContext->setContextProperty(QStringLiteral("auroraeTheme"), theme);
m_item = qobject_cast< QQuickItem* >(component->create(context));
m_item = qobject_cast< QQuickItem* >(component->create(m_qmlContext));
if (!m_item) {
if (component->isError()) {
const auto errors = component->errors();
......@@ -322,7 +324,7 @@ void Decoration::init()
QVariant visualParent = property("visualParent");
if (visualParent.isValid()) {
......@@ -27,6 +27,7 @@ class QOffscreenSurface;
class QOpenGLContext;
class QOpenGLFramebufferObject;
class QQmlComponent;
class QQmlContext;
class QQmlEngine;
class QQuickItem;
class QQuickRenderControl;
......@@ -82,7 +83,8 @@ private:
QImage m_buffer;
QRect m_contentRect; //the geometry of the part of the buffer that is not a shadow when buffer was created.
QPointer<QQuickWindow> m_view;
QQuickItem *m_item;
QQuickItem *m_item = nullptr;
QQmlContext *m_qmlContext = nullptr;
KWin::Borders *m_borders;
KWin::Borders *m_maximizedBorders;
KWin::Borders *m_extendedBorders;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment