diff --git a/src/OrcaSlicer.cpp b/src/OrcaSlicer.cpp index cbbc702fde..4a2cd1ab96 100644 --- a/src/OrcaSlicer.cpp +++ b/src/OrcaSlicer.cpp @@ -3182,7 +3182,7 @@ int CLI::run(int argc, char **argv) if (filament_options_with_variant.find(opt_key) != filament_options_with_variant.end()) { std::vector temp_variant_indice; temp_variant_indice.resize(new_variant_count, -1); - opt_vec_dst->set_with_restore_2(opt_vec_src, temp_variant_indice, old_start_indice[filament_index - 1], old_variant_count); + opt_vec_dst->set_with_restore_2(opt_vec_src, temp_variant_indice, old_start_indice[filament_index - 1], old_variant_count, true); if (opt_key == "filament_extruder_variant") new_variant_counts[filament_index - 1] = opt_vec_src->size(); diff --git a/src/libslic3r/Config.hpp b/src/libslic3r/Config.hpp index 13a70455bf..45bee05c2c 100644 --- a/src/libslic3r/Config.hpp +++ b/src/libslic3r/Config.hpp @@ -350,7 +350,7 @@ public: virtual void append(const ConfigOption *rhs) = 0; virtual void set(const ConfigOption* rhs, size_t start, size_t len) = 0; virtual void set_with_restore(const ConfigOptionVectorBase* rhs, std::vector& restore_index, int stride) = 0; - virtual void set_with_restore_2(const ConfigOptionVectorBase* rhs, std::vector& restore_index, int start, int len) = 0; + virtual void set_with_restore_2(const ConfigOptionVectorBase* rhs, std::vector& restore_index, int start, int len, bool skip_error = false) = 0; virtual void set_only_diff(const ConfigOptionVectorBase* rhs, std::vector& diff_index, int stride) = 0; virtual void set_with_nil(const ConfigOptionVectorBase* rhs, const ConfigOptionVectorBase* inherits, int stride) = 0; // Resize the vector of values, copy the newly added values from opt_default if provided. @@ -508,7 +508,7 @@ public: //restore_index: which index in this vector need to be restored //start: which index in this vector need to be replaced //count: how many items in this vector need to be replaced - virtual void set_with_restore_2(const ConfigOptionVectorBase* rhs, std::vector& restore_index, int start, int len) override + virtual void set_with_restore_2(const ConfigOptionVectorBase* rhs, std::vector& restore_index, int start, int len, bool skip_error = false) override { if (rhs->type() == this->type()) { //backup original ones @@ -527,10 +527,16 @@ public: } // Assign the new value from the rhs vector. - auto other = static_cast*>(rhs); + auto other = const_cast*>(static_cast*>(rhs)); - if (other->values.size() != (restore_index.size())) - throw ConfigurationError("ConfigOptionVector::set_with_restore_2(): Assigning from an vector with invalid restore_index size"); + if (other->values.size() != (restore_index.size())) { + if (skip_error) { + T default_v = other->values.front(); + other->values.resize(restore_index.size(), default_v); + } + else + throw ConfigurationError("ConfigOptionVector::set_with_restore_2(): Assigning from an vector with invalid restore_index size"); + } for (size_t i = 0; i < restore_index.size(); i++) { if ((restore_index[i] != -1)&&(restore_index[i] < backup_values.size())) {