Browse Source

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.
Lukáš Hejl 1 year ago
parent
commit
cda2446649
1 changed files with 4 additions and 4 deletions
  1. 4 4
      src/libslic3r/GCode.cpp

+ 4 - 4
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.