From cda2446649cb29ea8f9f16cdc8354f3a2c40e484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hejl?= Date: Mon, 22 Jan 2024 10:28:08 +0100 Subject: [PATCH] SPE-2120: Fix crash caused by using GCodeGenerator::last_position when it doesn't have an assigned value. This behavior was there for a long time, but it was uncovered when std::optional was used. --- src/libslic3r/GCode.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 9061d8bc27..62856612cc 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -2712,11 +2712,11 @@ static constexpr const double min_gcode_segment_length = 0.002; std::string GCodeGenerator::extrude_loop(const ExtrusionLoop &loop_src, const GCode::SmoothPathCache &smooth_path_cache, const std::string_view description, double speed) { // Extrude all loops CCW. - bool is_hole = loop_src.is_clockwise(); - Point seam_point = *this->last_position; - if (! m_config.spiral_vase && comment_is_perimeter(description)) { + bool is_hole = loop_src.is_clockwise(); + Point seam_point = this->last_position.has_value() ? *this->last_position : Point::Zero(); + if (!m_config.spiral_vase && comment_is_perimeter(description)) { assert(m_layer != nullptr); - seam_point = m_seam_placer.place_seam(m_layer, loop_src, m_config.external_perimeters_first, *this->last_position); + seam_point = m_seam_placer.place_seam(m_layer, loop_src, m_config.external_perimeters_first, seam_point); } // Because the G-code export has 1um resolution, don't generate segments shorter than 1.5 microns, // thus empty path segments will not be produced by G-code export.