From 211f53cebae66608f080e856c3bb8ec1b3136e7c Mon Sep 17 00:00:00 2001 From: Knud Dollereder Date: Wed, 26 Oct 2022 16:30:59 +0200 Subject: [PATCH] Prevent a crash on close The Destructor of the class Model::Private indirecly called modelAboutToBeDetached which did lead the FormEditor to try to access the already deleted ModelPrivate. This patch is a quick-crash-fix that prevents this by moving the detachAllViews call from the destructor of ModelPrivate to the destructor of Model. Note that a clean fix would probably make the access of ModelPrivate outside of Model impossible but this is outside the scope of this fix and left for a later exercise. Fixes: QDS-7587 Change-Id: I0d03423ae6eaf4d86eddba26ec5edb643ea5a51e Reviewed-by: Marco Bubke --- src/plugins/qmldesigner/designercore/model/model.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/plugins/qmldesigner/designercore/model/model.cpp b/src/plugins/qmldesigner/designercore/model/model.cpp index 32cf4173b22..5946b6cb238 100644 --- a/src/plugins/qmldesigner/designercore/model/model.cpp +++ b/src/plugins/qmldesigner/designercore/model/model.cpp @@ -88,10 +88,7 @@ ModelPrivate::ModelPrivate( m_currentTimelineNode = m_rootInternalNode; } -ModelPrivate::~ModelPrivate() -{ - detachAllViews(); -} +ModelPrivate::~ModelPrivate() = default; void ModelPrivate::detachAllViews() { @@ -1397,7 +1394,11 @@ Model::Model(const TypeName &typeName, int major, int minor, Model *metaInfoProx : d(std::make_unique(this, typeName, major, minor, metaInfoProxyModel)) {} -Model::~Model() = default; +Model::~Model() +{ + d->detachAllViews(); + d.reset(nullptr); +} const QList &Model::imports() const {