From d54e14a41d4d97a12b6de9518cfedc863f7f6617 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Tue, 14 May 2019 16:37:32 +0200 Subject: [PATCH] Fixed a crash on deleting objects due to the ObjectList accessing released data before the selection was updated on the GLScene. --- src/libslic3r/Model.cpp | 3 ++- src/slic3r/GUI/Plater.cpp | 14 ++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index fbcc3a04b..27335df7b 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -1521,7 +1521,8 @@ stl_stats ModelObject::get_object_stl_stats() const if (this->volumes.size() == 1) return this->volumes[0]->mesh.stl.stats; - stl_stats full_stats = this->volumes[0]->mesh.stl.stats; + stl_stats full_stats; + memset(&full_stats, 0, sizeof(stl_stats)); // fill full_stats from all objet's meshes for (ModelVolume* volume : this->volumes) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 0e45f13ce..c61d8a263 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2057,10 +2057,9 @@ void Plater::priv::remove(size_t obj_idx) view3D->enable_layers_editing(false); model.delete_object(obj_idx); - // Delete object from Sidebar list - sidebar->obj_list()->delete_object_from_list(obj_idx); - update(); + // Delete object from Sidebar list. Do it after update, so that the GLScene selection is updated with the modified model. + sidebar->obj_list()->delete_object_from_list(obj_idx); object_list_changed(); } @@ -2085,10 +2084,9 @@ void Plater::priv::reset() // Stop and reset the Print content. this->background_process.reset(); model.clear_objects(); - - // Delete all objects from list on c++ side - sidebar->obj_list()->delete_all_objects_from_list(); update(); + // Delete object from Sidebar list. Do it after update, so that the GLScene selection is updated with the modified model. + sidebar->obj_list()->delete_all_objects_from_list(); object_list_changed(); // The hiding of the slicing results, if shown, is not taken care by the background process, so we do it here @@ -3392,14 +3390,14 @@ void Plater::decrease_instances(size_t num) if (model_object->instances.size() > num) { for (size_t i = 0; i < num; ++ i) model_object->delete_last_instance(); + p->update(); + // Delete object from Sidebar list. Do it after update, so that the GLScene selection is updated with the modified model. sidebar().obj_list()->decrease_object_instances(obj_idx, num); } else { remove(obj_idx); } - p->update(); - if (!model_object->instances.empty()) p->get_selection().add_instance(obj_idx, (int)model_object->instances.size() - 1);