Fix potential crash found by the tests

Item::checkSanity() can be called via deleteLater when we don't
have a platform anymore
This commit is contained in:
Sergio Martins
2022-06-29 12:25:01 +01:00
parent 214e7d2013
commit a99c3e1b70
3 changed files with 17 additions and 1 deletions

View File

@@ -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;

View File

@@ -28,5 +28,12 @@ public:
/// to window activations and use a different style depending on activation state.
KDBindings::Signal<std::shared_ptr<View>> windowActivated;
KDBindings::Signal<std::shared_ptr<View>> windowDeactivated;
bool inDestruction() const
{
return m_inDestruction;
}
bool m_inDestruction = false;
};
}

View File

@@ -18,7 +18,8 @@
#include "kdbindings/signal.h"
#include "Window.h"
#include "../View_p.h"
#include "Platform.h"
#include "../Platform_p.h"
#include <QEvent>
#include <QDebug>
@@ -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;