From 644c828f007fba8dda4292dde432f29f69793362 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Fri, 26 Jan 2024 16:31:04 +0100 Subject: [PATCH] Fixed crash caused by changes related to issue #594 - deletion of CFloatingWidget caused crash when loading a state from XML --- src/DockManager.cpp | 1 + src/FloatingDockContainer.cpp | 18 ++++++++++++------ src/FloatingDockContainer.h | 7 +++++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/DockManager.cpp b/src/DockManager.cpp index 5d47394..06ed8cd 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -566,6 +566,7 @@ CDockManager::~CDockManager() auto FloatingWidgets = d->FloatingWidgets; for (auto FloatingWidget : FloatingWidgets) { + FloatingWidget->deleteContent(); delete FloatingWidget; } diff --git a/src/FloatingDockContainer.cpp b/src/FloatingDockContainer.cpp index f228476..e06e131 100644 --- a/src/FloatingDockContainer.cpp +++ b/src/FloatingDockContainer.cpp @@ -760,10 +760,22 @@ CFloatingDockContainer::CFloatingDockContainer(CDockWidget *DockWidget) : d->DockManager->notifyWidgetOrAreaRelocation(DockWidget); } + //============================================================================ CFloatingDockContainer::~CFloatingDockContainer() { ADS_PRINT("~CFloatingDockContainer"); + if (d->DockManager) + { + d->DockManager->removeFloatingWidget(this); + } + delete d; +} + + +//============================================================================ +void CFloatingDockContainer::deleteContent() +{ std::vector> areas; for (int i = 0; i != dockContainer()->dockAreaCount(); ++i) { @@ -788,12 +800,6 @@ CFloatingDockContainer::~CFloatingDockContainer() delete ptrWdg; } } - - if (d->DockManager) - { - d->DockManager->removeFloatingWidget(this); - } - delete d; } //============================================================================ diff --git a/src/FloatingDockContainer.h b/src/FloatingDockContainer.h index 2622767..7e6faec 100644 --- a/src/FloatingDockContainer.h +++ b/src/FloatingDockContainer.h @@ -146,6 +146,13 @@ protected: */ virtual void finishDragging() override; + /** + * This function deletes all dock widgets in it. + * This functions should be called only from dock manager in its + * destructor before deleting the floating widget + */ + void deleteContent(); + /** * Call this function if you just want to initialize the position * and size of the floating widget