From 71be87ecef222ad9033ffa7ac0b90f751bb12f44 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Wed, 29 Mar 2023 17:53:23 +0200 Subject: [PATCH] Fixed crash if toolchange G-code modifies final position, because the extruder was not set yet. --- src/libslic3r/GCode.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 4deaa2671f..599292acbe 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -6302,10 +6302,12 @@ Vec2d GCode::point_to_gcode(const Point &point) const // convert a model-space scaled point into G-code coordinates Point GCode::gcode_to_point(const Vec2d &point) const { - Vec2d extruder_offset = EXTRUDER_CONFIG(extruder_offset); - return Point( - scale_(point(0) - m_origin(0) + extruder_offset(0)), - scale_(point(1) - m_origin(1) + extruder_offset(1))); + Vec2d pt = point - m_origin; + if (const Extruder *extruder = m_writer.extruder(); extruder) + // This function may be called at the very start from toolchange G-code when the extruder is not assigned yet. + pt += m_config.extruder_offset.get_at(extruder->id()); + return scaled(pt); + } Vec2d GCode::point_to_gcode_quantized(const Point& point) const