From 242316e89def9c12bf744cf676f1bbd8dc13a1c9 Mon Sep 17 00:00:00 2001 From: supermerill Date: Wed, 16 Mar 2022 17:05:05 +0100 Subject: To avoid a crash when the config isn't correct, add a substitution. --- src/libslic3r/Config.cpp | 10 +++++++++- src/libslic3r/Config.hpp | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/libslic3r/Config.cpp b/src/libslic3r/Config.cpp index ee3fda467..f05d35d2d 100644 --- a/src/libslic3r/Config.cpp +++ b/src/libslic3r/Config.cpp @@ -827,11 +827,19 @@ ConfigSubstitutions ConfigBase::load(const boost::property_tree::ptree &tree, Fo { ConfigSubstitutionContext substitutions_ctxt(compatibility_rule); for (const boost::property_tree::ptree::value_type &v : tree) { + t_config_option_key opt_key = v.first; try { - t_config_option_key opt_key = v.first; this->set_deserialize(opt_key, v.second.get_value(), substitutions_ctxt); } catch (UnknownOptionException & /* e */) { // ignore + } catch (BadOptionValueException & e) { + if (compatibility_rule == ForwardCompatibilitySubstitutionRule::Disable) + throw e; + // log the error + const ConfigDef* def = this->def(); + if (def == nullptr) throw e; + const ConfigOptionDef* optdef = def->get(opt_key); + substitutions_ctxt.substitutions.emplace_back(optdef, v.second.get_value(), ConfigOptionUniquePtr(optdef->default_value->clone())); } } return std::move(substitutions_ctxt.substitutions); diff --git a/src/libslic3r/Config.hpp b/src/libslic3r/Config.hpp index e2506060e..1feace866 100644 --- a/src/libslic3r/Config.hpp +++ b/src/libslic3r/Config.hpp @@ -281,6 +281,8 @@ struct ConfigSubstitution { const ConfigOptionDef *opt_def { nullptr }; std::string old_value; ConfigOptionUniquePtr new_value; + ConfigSubstitution() = default; + ConfigSubstitution(const ConfigOptionDef* def, std::string old, ConfigOptionUniquePtr&& new_v) : opt_def(def), old_value(old), new_value(std::move(new_v)) {} }; using ConfigSubstitutions = std::vector; -- cgit v1.2.3