diff --git a/src/FffGcodeWriter.cpp b/src/FffGcodeWriter.cpp index d4c64cb685..04aacf5deb 100644 --- a/src/FffGcodeWriter.cpp +++ b/src/FffGcodeWriter.cpp @@ -1173,13 +1173,29 @@ FffGcodeWriter::ProcessLayerResult FffGcodeWriter::processLayer(const SliceDataS const std::vector& extruder_order = (layer_nr < 0) ? extruder_order_per_layer_negative_layers[extruder_order_per_layer_negative_layers.size() + layer_nr] : extruder_order_per_layer[layer_nr]; - const coord_t first_outer_wall_line_width = scene.extruders[extruder_order.front().extruder_nr].settings_.get("wall_line_width_0"); + size_t first_extruder; + if (extruder_order.size() > 0) + { + first_extruder = extruder_order.front().extruder_nr; + } + else + { + // find the last extruder used in the previous layer + size_t last_extruder_nr_layer = layer_nr - 1; + while (extruder_order_per_layer[last_extruder_nr_layer].size() == 0 && last_extruder_nr_layer >= 0) + { + last_extruder_nr_layer--; + } + first_extruder = extruder_order_per_layer[last_extruder_nr_layer].back().extruder_nr; + } + + const coord_t first_outer_wall_line_width = scene.extruders[first_extruder].settings_.get("wall_line_width_0"); LayerPlan& gcode_layer = *new LayerPlan( storage, layer_nr, z, layer_thickness, - extruder_order.front().extruder_nr, + first_extruder, fan_speed_layer_time_settings_per_extruder, comb_offset_from_outlines, first_outer_wall_line_width,