From 6b8f03ff1c8a83be88adf61486a6b47e4f3958b3 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Wed, 15 Oct 2014 00:59:26 +0200 Subject: [PATCH] Bugfix: crash in some circumstances when avoid_crossing_perimeters is enabled. #2266 --- xs/src/libslic3r/MotionPlanner.cpp | 13 +++++++++++++ xs/src/libslic3r/MotionPlanner.hpp | 1 + xs/xsp/MotionPlanner.xsp | 3 ++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/xs/src/libslic3r/MotionPlanner.cpp b/xs/src/libslic3r/MotionPlanner.cpp index b562a2832..dd626cda7 100644 --- a/xs/src/libslic3r/MotionPlanner.cpp +++ b/xs/src/libslic3r/MotionPlanner.cpp @@ -18,10 +18,17 @@ MotionPlanner::~MotionPlanner() delete *graph; } +size_t +MotionPlanner::islands_count() const +{ + return this->islands.size(); +} + void MotionPlanner::initialize() { if (this->initialized) return; + if (this->islands.empty()) return; // prevent initialization of empty BoundingBox ExPolygons expp; for (ExPolygons::const_iterator island = this->islands.begin(); island != this->islands.end(); ++island) { @@ -70,6 +77,12 @@ MotionPlanner::shortest_path(const Point &from, const Point &to, Polyline* polyl { if (!this->initialized) this->initialize(); + if (this->islands.empty()) { + polyline->points.push_back(from); + polyline->points.push_back(to); + return; + } + // Are both points in the same island? int island_idx = -1; for (ExPolygons::const_iterator island = this->islands.begin(); island != this->islands.end(); ++island) { diff --git a/xs/src/libslic3r/MotionPlanner.hpp b/xs/src/libslic3r/MotionPlanner.hpp index 78fd5c72b..b40ed2ef7 100644 --- a/xs/src/libslic3r/MotionPlanner.hpp +++ b/xs/src/libslic3r/MotionPlanner.hpp @@ -22,6 +22,7 @@ class MotionPlanner MotionPlanner(const ExPolygons &islands); ~MotionPlanner(); void shortest_path(const Point &from, const Point &to, Polyline* polyline); + size_t islands_count() const; private: ExPolygons islands; diff --git a/xs/xsp/MotionPlanner.xsp b/xs/xsp/MotionPlanner.xsp index ad29bc0f7..fc4bae715 100644 --- a/xs/xsp/MotionPlanner.xsp +++ b/xs/xsp/MotionPlanner.xsp @@ -8,7 +8,8 @@ %name{Slic3r::MotionPlanner} class MotionPlanner { MotionPlanner(ExPolygons islands); ~MotionPlanner(); - + + int islands_count(); Polyline* shortest_path(Point* from, Point* to) %code%{ RETVAL = new Polyline(); THIS->shortest_path(*from, *to, RETVAL); %}; };