From 356ed93ad782b41f380e8885f3e32a914e607ece Mon Sep 17 00:00:00 2001 From: PavelMikus Date: Wed, 16 Feb 2022 14:27:33 +0100 Subject: [PATCH] Raft layers cause SeamPlacer crash - fix --- src/libslic3r/GCode.cpp | 2 +- src/libslic3r/GCode/SeamPlacerNG.cpp | 10 +++++----- src/libslic3r/GCode/SeamPlacerNG.hpp | 3 +-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 4c7135103..e1d429488 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -2586,7 +2586,7 @@ std::string GCode::extrude_loop(ExtrusionLoop loop, std::string description, dou loop.split_at(last_pos, false); } else - m_seam_placer.place_seam(m_layer->object(), loop, m_layer->slice_z, m_layer_index, m_config.external_perimeters_first); + m_seam_placer.place_seam(m_layer, loop, m_config.external_perimeters_first); // clip the path to avoid the extruder to get exactly on the first point of the loop; // if polyline was shorter than the clipping distance we'd get a null polyline, so diff --git a/src/libslic3r/GCode/SeamPlacerNG.cpp b/src/libslic3r/GCode/SeamPlacerNG.cpp index 7e9037a80..fe7e7f2ae 100644 --- a/src/libslic3r/GCode/SeamPlacerNG.cpp +++ b/src/libslic3r/GCode/SeamPlacerNG.cpp @@ -703,12 +703,12 @@ void SeamPlacer::init(const Print &print) { } } -void SeamPlacer::place_seam(const PrintObject *po, ExtrusionLoop &loop, coordf_t unscaled_z, int layer_index, - bool external_first) { - assert(m_perimeter_points_trees_per_object.find(po) != nullptr); - assert(m_perimeter_points_per_object.find(po) != nullptr); +void SeamPlacer::place_seam(const Layer* layer, ExtrusionLoop &loop, bool external_first) { + const PrintObject* po = layer->object(); + //NOTE this is necessary, since layer->id() is quite unreliable + size_t layer_index = std::max(0,int(layer->id()) - int(po->slicing_parameters().raft_layers())); + double unscaled_z = layer->slice_z; - assert(layer_index >= 0); const auto &perimeter_points_tree = *m_perimeter_points_trees_per_object[po][layer_index]; const auto &perimeter_points = m_perimeter_points_per_object[po][layer_index]; diff --git a/src/libslic3r/GCode/SeamPlacerNG.hpp b/src/libslic3r/GCode/SeamPlacerNG.hpp index ee85f94ab..3379a1935 100644 --- a/src/libslic3r/GCode/SeamPlacerNG.hpp +++ b/src/libslic3r/GCode/SeamPlacerNG.hpp @@ -97,8 +97,7 @@ public: void init(const Print &print); - void place_seam(const PrintObject *po, ExtrusionLoop &loop, coordf_t unscaled_z, int layer_index, - bool external_first); + void place_seam(const Layer* layer, ExtrusionLoop &loop, bool external_first); private: void gather_seam_candidates(const PrintObject* po, const SeamPlacerImpl::GlobalModelInfo& global_model_info);