From 8806442f551d2c1f01457fc44f9784e21565f174 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Tue, 13 Jun 2023 10:20:45 +0200 Subject: [PATCH] PlaceholderParser on G-code export: 1) added "num_extruders" placeholder 2) changed "is_extruder_used" vector to be always minimum 256 elements long with the non-existent extruder values set to zero. This is wasteful, but necessary until we change the PlaceholderParser handling of vector values to not substitute missing elements with the zero'th value. --- src/libslic3r/GCode.cpp | 8 ++++++-- src/libslic3r/PlaceholderParser.cpp | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 54177d213..d65e0aa9f 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -1296,8 +1296,12 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato this->placeholder_parser().set("first_layer_print_min", new ConfigOptionFloats({ bbox.min.x(), bbox.min.y() })); this->placeholder_parser().set("first_layer_print_max", new ConfigOptionFloats({ bbox.max.x(), bbox.max.y() })); this->placeholder_parser().set("first_layer_print_size", new ConfigOptionFloats({ bbox.size().x(), bbox.size().y() })); - - std::vector is_extruder_used(print.config().nozzle_diameter.size(), 0); + this->placeholder_parser().set("num_extruders", int(print.config().nozzle_diameter.values.size())); + // PlaceholderParser currently substitues non-existent vector values with the zero'th value, which is harmful in the case of "is_extruder_used[]" + // as Slicer may lie about availability of such non-existent extruder. + // We rather sacrifice 256B of memory before we change the behavior of the PlaceholderParser, which should really only fill in the non-existent + // vector elements for filament parameters. + std::vector is_extruder_used(std::max(size_t(255), print.config().nozzle_diameter.size()), 0); for (unsigned int extruder_id : tool_ordering.all_extruders()) is_extruder_used[extruder_id] = true; this->placeholder_parser().set("is_extruder_used", new ConfigOptionBools(is_extruder_used)); diff --git a/src/libslic3r/PlaceholderParser.cpp b/src/libslic3r/PlaceholderParser.cpp index 786f4093c..40126421c 100644 --- a/src/libslic3r/PlaceholderParser.cpp +++ b/src/libslic3r/PlaceholderParser.cpp @@ -1090,6 +1090,7 @@ namespace client static void scalar_variable_assign_scalar(const MyContext *ctx, OptWithPos &lhs, const expr &rhs) { + assert(! ctx->skipping()); assert(lhs.opt->is_scalar()); check_writable(ctx, lhs); ConfigOption *wropt = const_cast(lhs.opt); @@ -1121,6 +1122,7 @@ namespace client static void vector_variable_element_assign_scalar(const MyContext *ctx, OptWithPos &lhs, const expr &rhs) { + assert(! ctx->skipping()); assert(lhs.opt->is_vector()); check_writable(ctx, lhs); if (! lhs.has_index()) @@ -1158,6 +1160,7 @@ namespace client static void vector_variable_assign_expr_with_count(const MyContext *ctx, OptWithPos &lhs, const expr &rhs_count, const expr &rhs_value) { + assert(! ctx->skipping()); size_t count = evaluate_count(rhs_count); auto *opt = const_cast(lhs.opt); switch (lhs.opt->type()) {