Fix a crash-on-close in the dockmanager

The destructor of DockManager deletes floatingwidgets in a for loop.
The destructor of these floatingWidgets calls back to the DockManager
and alters the list it is currently iterating over.
This is now quick-fixed by deferring the deletion by using a temporal
vector.

Change-Id: I40b77ea505a5fc7506117dc16476e2e498ce4aef
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Knud Dollereder
2021-06-09 16:00:51 +02:00
parent 4c699d5181
commit 0a49728727

View File

@@ -357,13 +357,20 @@ namespace ADS
save(); save();
saveStartupWorkspace(); saveStartupWorkspace();
// Using a temporal vector since the destructor of
// FloatingDockWidgetContainer alters d->m_floatingWidgets.
std::vector<FloatingDockContainer *> aboutToDeletes;
for (auto floatingWidget : qAsConst(d->m_floatingWidgets)) { for (auto floatingWidget : qAsConst(d->m_floatingWidgets)) {
/* There have been crashes with partially destructed widgets in if (floatingWidget)
m_floatingWidgets. Those do not have a parent. */ aboutToDeletes.push_back(floatingWidget);
if (floatingWidget && floatingWidget->parent() == this)
delete floatingWidget.data();
} }
for (auto del : aboutToDeletes) {
delete del;
}
d->m_floatingWidgets.clear(); d->m_floatingWidgets.clear();
delete d; delete d;
} }