From 9c93e52c8f313d4448006f06718a6dfdc5ec758a Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 8 Nov 2014 12:56:14 +0100 Subject: [PATCH] Workaround Clipper changing point coordinates while performing simplify_polygons(), thus causing a crash in Slic3r. #2306 --- lib/Slic3r/GCode.pm | 11 +++++++++-- xs/src/libslic3r/ExtrusionEntity.cpp | 6 +++--- xs/src/libslic3r/ExtrusionEntity.hpp | 2 +- xs/xsp/ExtrusionLoop.xsp | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/Slic3r/GCode.pm b/lib/Slic3r/GCode.pm index 573d14bcb..03ef4ea94 100644 --- a/lib/Slic3r/GCode.pm +++ b/lib/Slic3r/GCode.pm @@ -148,12 +148,19 @@ sub extrude_loop { if ($self->config->seam_position eq 'nearest') { @candidates = @$polygon if !@candidates; $point = $last_pos->nearest_point(\@candidates); - $loop->split_at_vertex($point); + if (!$loop->split_at_vertex($point)) { + # On 32-bit Linux, Clipper will change some point coordinates by 1 unit + # while performing simplify_polygons(), thus split_at_vertex() won't + # find them anymore. + $loop->split_at($point); + } } elsif (@candidates) { my @non_overhang = grep !$loop->has_overhang_point($_), @candidates; @candidates = @non_overhang if @non_overhang; $point = $last_pos->nearest_point(\@candidates); - $loop->split_at_vertex($point); + if (!$loop->split_at_vertex($point)) { + $loop->split_at($point); + } } else { $point = $last_pos->projection_onto_polygon($polygon); $loop->split_at($point); diff --git a/xs/src/libslic3r/ExtrusionEntity.cpp b/xs/src/libslic3r/ExtrusionEntity.cpp index 725693fae..34372c72b 100644 --- a/xs/src/libslic3r/ExtrusionEntity.cpp +++ b/xs/src/libslic3r/ExtrusionEntity.cpp @@ -224,7 +224,7 @@ ExtrusionLoop::length() const return len; } -void +bool ExtrusionLoop::split_at_vertex(const Point &point) { for (ExtrusionPaths::iterator path = this->paths.begin(); path != this->paths.end(); ++path) { @@ -261,10 +261,10 @@ ExtrusionLoop::split_at_vertex(const Point &point) // we can now override the old path list with the new one and stop looping this->paths = new_paths; } - return; + return true; } } - CONFESS("Point not found"); + return false; } void diff --git a/xs/src/libslic3r/ExtrusionEntity.hpp b/xs/src/libslic3r/ExtrusionEntity.hpp index cbcd80d52..aad36cb3d 100644 --- a/xs/src/libslic3r/ExtrusionEntity.hpp +++ b/xs/src/libslic3r/ExtrusionEntity.hpp @@ -92,7 +92,7 @@ class ExtrusionLoop : public ExtrusionEntity Point last_point() const; void polygon(Polygon* polygon) const; double length() const; - void split_at_vertex(const Point &point); + bool split_at_vertex(const Point &point); void split_at(const Point &point); void clip_end(double distance, ExtrusionPaths* paths) const; bool has_overhang_point(const Point &point) const; diff --git a/xs/xsp/ExtrusionLoop.xsp b/xs/xsp/ExtrusionLoop.xsp index e7f4f0319..944dd25ea 100644 --- a/xs/xsp/ExtrusionLoop.xsp +++ b/xs/xsp/ExtrusionLoop.xsp @@ -20,7 +20,7 @@ void append(ExtrusionPath* path) %code{% THIS->paths.push_back(*path); %}; double length(); - void split_at_vertex(Point* point) + bool split_at_vertex(Point* point) %code{% THIS->split_at_vertex(*point); %}; void split_at(Point* point) %code{% THIS->split_at(*point); %};