diff --git a/lib/Slic3r/Geometry.pm b/lib/Slic3r/Geometry.pm index 6652a49d3..4166fa49c 100644 --- a/lib/Slic3r/Geometry.pm +++ b/lib/Slic3r/Geometry.pm @@ -654,7 +654,7 @@ sub angle3points { sub polyline_remove_parallel_continuous_edges { my ($points, $isPolygon) = @_; - for (my $i = $isPolygon ? 0 : 2; $i <= $#$points; $i++) { + for (my $i = $isPolygon ? 0 : 2; $i <= $#$points && @$points >= 3; $i++) { if (Slic3r::Geometry::lines_parallel([$points->[$i-2], $points->[$i-1]], [$points->[$i-1], $points->[$i]])) { # we can remove $points->[$i-1] splice @$points, $i-1, 1; diff --git a/lib/Slic3r/Polygon.pm b/lib/Slic3r/Polygon.pm index 1c5d9021d..b3bab44ae 100644 --- a/lib/Slic3r/Polygon.pm +++ b/lib/Slic3r/Polygon.pm @@ -38,6 +38,7 @@ sub lines { sub cleanup { my $self = shift; $self->merge_continuous_lines; + return @$self >= 3; } sub merge_continuous_lines { diff --git a/lib/Slic3r/TriangleMesh.pm b/lib/Slic3r/TriangleMesh.pm index 1d68804a1..e67c514ef 100644 --- a/lib/Slic3r/TriangleMesh.pm +++ b/lib/Slic3r/TriangleMesh.pm @@ -166,7 +166,7 @@ sub make_loops { pop @points; Slic3r::debugf " Discovered polygon of %d points\n", scalar(@points); push @polygons, Slic3r::Polygon->new(@points); - $polygons[-1]->cleanup; + pop @polygons if !$polygons[-1]->cleanup; } };