Skip to content

Commit

Permalink
slic3r: address sanitizer cleanup around wipe tower deletion
Browse files Browse the repository at this point in the history
When determining whether or not we need to update the object list, we check
all of the objects that are being deleted to see if they're a wipe tower.
Unfortunately, by the time we check, the objects have already been deleted,
and the memory has been freed!  Avoid this by writing down for deleted
objects whether they are wipe towers, and if they were, we can indeed skip
updating the object list.
  • Loading branch information
jwise authored and lanewei120 committed Feb 1, 2023
1 parent 0078c2a commit a082ce5
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/slic3r/GUI/GLCanvas3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2167,15 +2167,16 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re

struct GLVolumeState {
GLVolumeState() :
volume_idx(size_t(-1)) {}
volume_idx(size_t(-1)), was_wipe_tower(0) {}
GLVolumeState(const GLVolume* volume, unsigned int volume_idx) :
composite_id(volume->composite_id), volume_idx(volume_idx) {}
composite_id(volume->composite_id), volume_idx(volume_idx), was_wipe_tower(volume->is_wipe_tower) {}
GLVolumeState(const GLVolume::CompositeID &composite_id) :
composite_id(composite_id), volume_idx(size_t(-1)) {}
composite_id(composite_id), volume_idx(size_t(-1)), was_wipe_tower(0) {}

GLVolume::CompositeID composite_id;
// Volume index in the old GLVolume vector.
size_t volume_idx;
bool was_wipe_tower;
};

// SLA steps to pull the preview meshes for.
Expand Down Expand Up @@ -2378,8 +2379,21 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
}
}
for (int temp_idx = vol_idx; temp_idx < m_volumes.volumes.size() && !update_object_list; temp_idx++) {
if (!m_volumes.volumes[temp_idx]->is_wipe_tower)
// Volumes in m_volumes might not exist anymore, so we cannot
// directly check if they are is_wipe_towers, for which we do
// not want to update the object list. Instead, we do a kind of
// slow thing of seeing if they were in the deleted list, and if
// so, if they were a wipe tower.
bool was_deleted_wipe_tower = false;
for (int del_idx = 0; del_idx < deleted_volumes.size(); del_idx++) {
if (deleted_volumes[del_idx].volume_idx == temp_idx && deleted_volumes[del_idx].was_wipe_tower) {
was_deleted_wipe_tower = true;
break;
}
}
if (!was_deleted_wipe_tower) {
update_object_list = true;
}
}
for (int temp_idx = vol_idx; temp_idx < glvolumes_new.size() && !update_object_list; temp_idx++) {
if (!glvolumes_new[temp_idx]->is_wipe_tower)
Expand Down

0 comments on commit a082ce5

Please sign in to comment.