From 2d428198b14b7025775212264ddba68ca20b5d7a Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Mon, 4 Jan 2021 11:13:10 +0100 Subject: [PATCH] Fix of 2.3 rc1 can't load its own 3mf files (if they contain custom gcode) #5550 The issue was handling of the special "default_filament_profile" vector, which is not being normalized in length to the number of extruders, as this vector is being shown to the user at the Printer dependencies page, and we don't want to present empty fields there, if the default filament profile was not defined in the system preset. --- src/libslic3r/Preset.cpp | 26 +++++++++++++++----------- src/libslic3r/PresetBundle.cpp | 7 +++---- src/libslic3r/PrintConfig.cpp | 2 ++ 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index af6b50215..c24033df2 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -1152,18 +1152,22 @@ inline t_config_option_keys deep_diff(const ConfigBase &config_this, const Confi if (this_opt != nullptr && other_opt != nullptr && *this_opt != *other_opt) { if (opt_key == "bed_shape" || opt_key == "thumbnails" || opt_key == "compatible_prints" || opt_key == "compatible_printers") { + // Scalar variable, or a vector variable, which is independent from number of extruders, + // thus the vector is presented to the user as a single input. diff.emplace_back(opt_key); - continue; - } - switch (other_opt->type()) - { - case coInts: add_correct_opts_to_diff(opt_key, diff, config_other, config_this); break; - case coBools: add_correct_opts_to_diff(opt_key, diff, config_other, config_this); break; - case coFloats: add_correct_opts_to_diff(opt_key, diff, config_other, config_this); break; - case coStrings: add_correct_opts_to_diff(opt_key, diff, config_other, config_this); break; - case coPercents:add_correct_opts_to_diff(opt_key, diff, config_other, config_this); break; - case coPoints: add_correct_opts_to_diff(opt_key, diff, config_other, config_this); break; - default: diff.emplace_back(opt_key); break; + } else if (opt_key == "default_filament_profile") { + // Ignore this field, it is not presented to the user, therefore showing a "modified" flag for this parameter does not help. + // Also the length of this field may differ, which may lead to a crash if the block below is used. + } else { + switch (other_opt->type()) { + case coInts: add_correct_opts_to_diff(opt_key, diff, config_other, config_this); break; + case coBools: add_correct_opts_to_diff(opt_key, diff, config_other, config_this); break; + case coFloats: add_correct_opts_to_diff(opt_key, diff, config_other, config_this); break; + case coStrings: add_correct_opts_to_diff(opt_key, diff, config_other, config_this); break; + case coPercents:add_correct_opts_to_diff(opt_key, diff, config_other, config_this); break; + case coPoints: add_correct_opts_to_diff(opt_key, diff, config_other, config_this); break; + default: diff.emplace_back(opt_key); break; + } } } } diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index ae6a77139..1f1d11866 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -86,9 +86,8 @@ PresetBundle::PresetBundle() : preset.config.optptr(key, true); if (i == 0) { preset.config.optptr("default_print_profile", true); - preset.config.option("default_filament_profile", true)->values = { "" }; - } - else { + preset.config.option("default_filament_profile", true); + } else { preset.config.optptr("default_sla_print_profile", true); preset.config.optptr("default_sla_material_profile", true); } @@ -752,7 +751,7 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool switch (printer_technology) { case ptFFF: config.option("default_print_profile", true); - config.option("default_filament_profile", true)->values.resize(num_extruders, std::string()); + config.option("default_filament_profile", true); break; case ptSLA: config.option("default_sla_print_profile", true); diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 76bae268b..b3084f550 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -3378,6 +3378,8 @@ void DynamicPrintConfig::set_num_extruders(unsigned int num_extruders) const auto &defaults = FullPrintConfig::defaults(); for (const std::string &key : print_config_def.extruder_option_keys()) { if (key == "default_filament_profile") + // Don't resize this field, as it is presented to the user at the "Dependencies" page of the Printer profile and we don't want to present + // empty fields there, if not defined by the system profile. continue; auto *opt = this->option(key, false); assert(opt != nullptr);