Fixed crashes when deleting objects

This commit is contained in:
Enrico Turri 2018-11-14 11:22:13 +01:00
parent a56cee5f60
commit 86c1f5b417
2 changed files with 14 additions and 9 deletions

View file

@ -1182,20 +1182,23 @@ void ObjectList::delete_from_model_and_list(const ItemType type, const int obj_i
void ObjectList::delete_from_model_and_list(const std::vector<ItemForDelete>& items_for_delete) void ObjectList::delete_from_model_and_list(const std::vector<ItemForDelete>& items_for_delete)
{ {
for (auto& item : items_for_delete) if (items_for_delete.empty())
return;
for (std::vector<ItemForDelete>::const_reverse_iterator item = items_for_delete.rbegin(); item != items_for_delete.rend(); ++item)
{ {
if ( !(item.type&(itObject|itVolume|itInstance)) ) if (!(item->type&(itObject | itVolume | itInstance)))
continue; continue;
if (item.type&itObject) { if (item->type&itObject) {
del_object(item.obj_idx); del_object(item->obj_idx);
m_objects_model->Delete(m_objects_model->GetItemById(item.obj_idx)); m_objects_model->Delete(m_objects_model->GetItemById(item->obj_idx));
} }
else { else {
del_subobject_from_object(item.obj_idx, item.sub_obj_idx, item.type); del_subobject_from_object(item->obj_idx, item->sub_obj_idx, item->type);
if (item.type&itVolume) if (item->type&itVolume)
m_objects_model->Delete(m_objects_model->GetItemByVolumeId(item.obj_idx, item.sub_obj_idx)); m_objects_model->Delete(m_objects_model->GetItemByVolumeId(item->obj_idx, item->sub_obj_idx));
else else
m_objects_model->Delete(m_objects_model->GetItemByInstanceId(item.obj_idx, item.sub_obj_idx)); m_objects_model->Delete(m_objects_model->GetItemByInstanceId(item->obj_idx, item->sub_obj_idx));
} }
} }
part_selection_changed(); part_selection_changed();

View file

@ -1470,6 +1470,8 @@ void Plater::priv::remove(size_t obj_idx)
void Plater::priv::delete_object_from_model(size_t obj_idx) void Plater::priv::delete_object_from_model(size_t obj_idx)
{ {
model.delete_object(obj_idx); model.delete_object(obj_idx);
object_list_changed();
update();
} }
void Plater::priv::reset() void Plater::priv::reset()