Fix a crash deleting or merging a multi-part object on macOS (#17825)

The object list deletes an object's ModelObject before its row, and removes the
row's part rows one by one. On macOS each removal makes the outline reload the
object row at once, and GetChildren's import order read the freed ModelObject.
Deleting a multi-part object, or merging its parts with Mesh boolean, crashed
when that memory had been reused.

GetChildren now reads the row's object only while the model still holds it
(ObjectDataViewModel::live_model_object, a pointer comparison). The import order
read came in with #17050, so no release carries the crash.
This commit is contained in:
Hanan V authored and GitHub committed 2026-11-24 15:48:45 -06:00
1 parent 3f90d6ccf6
commit e56fd1ed44
3 files changed
+27 -2

No files matched your search

+10 -2
View File
@@ -2092,6 +2092,13 @@ bool ObjectDataViewModel::IsContainer(const wxDataViewItem &item) const
return node->IsContainer();
}
const ModelObject* ObjectDataViewModel::live_model_object(const ModelObject* row_object, const std::vector<ModelObject*>& model_objects)
{
if (row_object == nullptr)
return nullptr;
return std::find(model_objects.begin(), model_objects.end(), row_object) != model_objects.end() ? row_object : nullptr;
}
unsigned int ObjectDataViewModel::GetChildren(const wxDataViewItem &parent, wxDataViewItemArray &array) const
{
ObjectDataViewModelNode *node = static_cast<ObjectDataViewModelNode*>(parent.GetID());
@@ -2119,8 +2126,9 @@ unsigned int ObjectDataViewModel::GetChildren(const wxDataViewItem &parent, wxDa
std::vector<ObjectDataViewModelNode*> children;
for (auto* child : node->GetChildren())
children.push_back(child);
if (node->m_type == itObject && node->m_model_object != nullptr) {
const ModelObject& object = *node->m_model_object;
const ModelObject* live_object = node->m_type == itObject ? live_model_object(node->m_model_object, wxGetApp().model().objects) : nullptr;
if (live_object != nullptr) {
const ModelObject& object = *live_object;
if (std::any_of(object.volumes.begin(), object.volumes.end(), [](const ModelVolume* volume) {
return volume->import_display_order >= 0;
})) {