Merge pull request #21965 from tetektoza/fix/21861_crashes_selection_during_deletion

Core: Fix crashes during item deletion in specific selection order
This commit is contained in:
Kacper Donat
2025-06-17 00:39:17 +02:00
committed by GitHub

View File

@@ -4016,6 +4016,9 @@ void TreeWidget::_slotDeleteObject(const Gui::ViewProviderDocumentObject& view,
TREE_LOG("delete object " << obj->getFullName());
// Block all selection signals during deletion to prevent cascading selection change events
// during item creation or deletion
bool lock = blockSelection(true);
bool needUpdate = false;
for (const auto& data : itEntry->second) {
@@ -4029,13 +4032,11 @@ void TreeWidget::_slotDeleteObject(const Gui::ViewProviderDocumentObject& view,
if (obj->getDocument() == doc)
docItem->_ParentMap.erase(obj);
bool lock = blockSelection(true);
for (auto cit = items.begin(), citNext = cit; cit != items.end(); cit = citNext) {
++citNext;
(*cit)->myOwner = nullptr;
delete* cit;
}
blockSelection(lock);
// Check for any child of the deleted object that is not in the tree, and put it
// under document item.
@@ -4062,6 +4063,9 @@ void TreeWidget::_slotDeleteObject(const Gui::ViewProviderDocumentObject& view,
}
ObjectTable.erase(itEntry);
// Restore signal state
blockSelection(lock);
if (needUpdate)
_updateStatus();
}
@@ -5356,6 +5360,11 @@ enum Status {
void DocumentObjectItem::testStatus(bool resetStatus, QIcon& icon1, QIcon& icon2)
{
// guard against calling this during destruction when tree widget may be nullptr
if (!treeWidget()) {
return;
}
App::DocumentObject* pObject = object()->getObject();
int visible = -1;