Skip to content

Commit

Permalink
Split object : Check if new objects don't have a zero volume
Browse files Browse the repository at this point in the history
Related to :
 * prusa3d#8931 - Split to objects crashes Prusa Slicer
 * SPE-1221(https://dev.prusa3d.com/browse/SPE-1221) - Split to objects fail
  • Loading branch information
YuSanka committed Sep 23, 2022
1 parent 70be93d commit 7a1c118
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/libslic3r/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,7 @@ void ModelObject::split(ModelObjectPtrs* new_objects)
size_t counter = 1;
for (TriangleMesh &mesh : meshes) {
// FIXME: crashes if not satisfied
if (mesh.facets_count() < 3)
if (mesh.facets_count() < 3 || mesh.has_zero_volume())
continue;

// XXX: this seems to be the only real usage of m_model, maybe refactor this so that it's not needed?
Expand Down Expand Up @@ -1833,7 +1833,7 @@ size_t ModelVolume::split(unsigned int max_extruders)
const Vec3d offset = this->get_offset();

for (TriangleMesh &mesh : meshes) {
if (mesh.empty())
if (mesh.empty() || mesh.has_zero_volume())
// Repair may have removed unconnected triangles, thus emptying the mesh.
continue;

Expand Down
8 changes: 8 additions & 0 deletions src/libslic3r/TriangleMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,14 @@ bool TriangleMesh::is_splittable() const
return its_is_splittable(this->its);
}

bool TriangleMesh::has_zero_volume() const
{
const Vec3d sz = size();
const double volume_val = sz.x() * sz.y() * sz.z();

return is_approx(volume_val, 0.0);
}

std::vector<TriangleMesh> TriangleMesh::split() const
{
std::vector<indexed_triangle_set> itss = its_split(this->its);
Expand Down
1 change: 1 addition & 0 deletions src/libslic3r/TriangleMesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class TriangleMesh
bool empty() const { return this->facets_count() == 0; }
bool repaired() const;
bool is_splittable() const;
bool has_zero_volume() const;
// Estimate of the memory occupied by this structure, important for keeping an eye on the Undo / Redo stack allocation.
size_t memsize() const;

Expand Down

0 comments on commit 7a1c118

Please sign in to comment.