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.
This commit is contained in:
Lukáš Hejl 2024-01-22 10:28:08 +01:00
parent 6ff8537ff4
commit cda2446649

View File

@ -2713,10 +2713,10 @@ std::string GCodeGenerator::extrude_loop(const ExtrusionLoop &loop_src, const GC
{ {
// Extrude all loops CCW. // Extrude all loops CCW.
bool is_hole = loop_src.is_clockwise(); bool is_hole = loop_src.is_clockwise();
Point seam_point = *this->last_position; Point seam_point = this->last_position.has_value() ? *this->last_position : Point::Zero();
if (! m_config.spiral_vase && comment_is_perimeter(description)) { if (!m_config.spiral_vase && comment_is_perimeter(description)) {
assert(m_layer != nullptr); 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, // 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. // thus empty path segments will not be produced by G-code export.