From 788cbebcfc7e83e9b7131525a4d871c73ae47294 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 8 May 2017 21:09:37 +0200 Subject: [PATCH] Bugfix: crash when optimizing bridges. #3928 --- xs/src/libslic3r/LayerRegion.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/xs/src/libslic3r/LayerRegion.cpp b/xs/src/libslic3r/LayerRegion.cpp index 5b4a6cc5c..9ba33d236 100644 --- a/xs/src/libslic3r/LayerRegion.cpp +++ b/xs/src/libslic3r/LayerRegion.cpp @@ -74,17 +74,17 @@ LayerRegion::process_external_surfaces() Surfaces &surfaces = this->fill_surfaces.surfaces; for (size_t j = 0; j < surfaces.size(); ++j) { - Surface &surface = surfaces[j]; + // we don't get any reference to surface because it would be invalidated + // by the erase() call below - if (this->layer()->lower_layer != NULL && surface.is_bridge()) { + if (this->layer()->lower_layer != NULL && surfaces[j].is_bridge()) { // If this bridge has one or more holes that are internal surfaces // (thus not visible from the outside), like a slab sustained by // pillars, include them in the bridge in order to have better and // more continuous bridging. - Polygons &holes = surface.expolygon.holes; - for (int i = 0; i < holes.size(); ++i) { + for (int i = 0; i < surfaces[j].expolygon.holes.size(); ++i) { // reverse the hole and consider it a polygon - Polygon h = holes[i]; + Polygon h = surfaces[j].expolygon.holes[i]; h.reverse(); // Is this hole fully contained in the layer slices? @@ -94,10 +94,12 @@ LayerRegion::process_external_surfaces() if (k == j) continue; if (h.contains(surfaces[k].expolygon.contour.first_point())) { surfaces.erase(surfaces.begin() + k); + if (j > k) --j; --k; } } + Polygons &holes = surfaces[j].expolygon.holes; holes.erase(holes.begin() + i); --i; }