From a99c3e1b70ba9d831b611e14579ef2b043d12c64 Mon Sep 17 00:00:00 2001 From: Sergio Martins Date: Wed, 29 Jun 2022 12:25:01 +0100 Subject: [PATCH] Fix potential crash found by the tests Item::checkSanity() can be called via deleteLater when we don't have a platform anymore --- src/Platform.cpp | 1 + src/private/Platform_p.h | 7 +++++++ src/private/multisplitter/Item.cpp | 10 +++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Platform.cpp b/src/Platform.cpp index c874cd20..5172d690 100644 --- a/src/Platform.cpp +++ b/src/Platform.cpp @@ -118,6 +118,7 @@ void Platform::tests_initPlatform(int &argc, char **argv, KDDockWidgets::Fronten void Platform::tests_deinitPlatform() { auto plat = Platform::instance(); + plat->d->m_inDestruction = true; plat->tests_deinitPlatform_impl(); delete plat; diff --git a/src/private/Platform_p.h b/src/private/Platform_p.h index 730d84b2..6109ca17 100644 --- a/src/private/Platform_p.h +++ b/src/private/Platform_p.h @@ -28,5 +28,12 @@ public: /// to window activations and use a different style depending on activation state. KDBindings::Signal> windowActivated; KDBindings::Signal> windowDeactivated; + + bool inDestruction() const + { + return m_inDestruction; + } + + bool m_inDestruction = false; }; } diff --git a/src/private/multisplitter/Item.cpp b/src/private/multisplitter/Item.cpp index b258df47..bf37c848 100644 --- a/src/private/multisplitter/Item.cpp +++ b/src/private/multisplitter/Item.cpp @@ -18,7 +18,8 @@ #include "kdbindings/signal.h" #include "Window.h" #include "../View_p.h" - +#include "Platform.h" +#include "../Platform_p.h" #include #include @@ -1002,6 +1003,13 @@ bool ItemBoxContainer::checkSanity() { d->m_checkSanityScheduled = false; + auto plat = Platform::instance(); + if (!plat || plat->d->inDestruction()) { + // checkSanity() can be called with deleteLater(), so check if we still + // have a platform + return true; + } + if (!hostView()) { /// This is a dummy ItemBoxContainer, just return true return true;