FIX: CLI: fix the crash issue when load user config

jira: no-jira
Change-Id: I7b20c9c807150b45798aa036a1cbcb3c5aa1c9ae
(cherry picked from commit cb63ddfb6875bfa1fdbe6276d3e7a72a6776a4bc)
This commit is contained in:
lane.wei
2025-10-15 12:38:56 +08:00
committed by Noisyfox
parent dd7d12ed8b
commit 5d84c38b09
2 changed files with 12 additions and 6 deletions

View File

@@ -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<int> 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();

View File

@@ -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<int>& restore_index, int stride) = 0;
virtual void set_with_restore_2(const ConfigOptionVectorBase* rhs, std::vector<int>& restore_index, int start, int len) = 0;
virtual void set_with_restore_2(const ConfigOptionVectorBase* rhs, std::vector<int>& restore_index, int start, int len, bool skip_error = false) = 0;
virtual void set_only_diff(const ConfigOptionVectorBase* rhs, std::vector<int>& 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<int>& restore_index, int start, int len) override
virtual void set_with_restore_2(const ConfigOptionVectorBase* rhs, std::vector<int>& 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<const ConfigOptionVector<T>*>(rhs);
auto other = const_cast<ConfigOptionVector<T>*>(static_cast<const ConfigOptionVector<T>*>(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())) {