From 53bd39d80e4e8d10f9f8e3ad606b7b25d3945e47 Mon Sep 17 00:00:00 2001 From: supermerill Date: Fri, 29 Mar 2019 11:37:44 +0100 Subject: [PATCH] better config check & error message --- src/libslic3r/Config.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/Config.cpp b/src/libslic3r/Config.cpp index 741b0e9d2..efb381ca8 100644 --- a/src/libslic3r/Config.cpp +++ b/src/libslic3r/Config.cpp @@ -437,10 +437,15 @@ double ConfigBase::get_abs_value(const t_config_option_key &opt_key) const { // Get stored option value. const ConfigOption *raw_opt = this->option(opt_key); - assert(raw_opt != nullptr); + if (raw_opt == nullptr) { + std::stringstream ss; ss << "You can't define an option that need " << opt_key << " without defining it!"; + throw std::runtime_error(ss.str()); + } if (raw_opt->type() == coFloat) return static_cast(raw_opt)->value; if (raw_opt->type() == coFloatOrPercent) { + if(!static_cast(raw_opt)->percent) + return static_cast(raw_opt)->value; // Get option definition. const ConfigDef *def = this->def(); if (def == nullptr) @@ -453,7 +458,8 @@ double ConfigBase::get_abs_value(const t_config_option_key &opt_key) const return opt_def->ratio_over.empty() ? 0. : static_cast(raw_opt)->get_abs_value(this->get_abs_value(opt_def->ratio_over)); } - throw std::runtime_error("ConfigBase::get_abs_value(): Not a valid option type for get_abs_value()"); + std::stringstream ss; ss << "ConfigBase::get_abs_value(): "<< opt_key<<" has not a valid option type for get_abs_value()"; + throw std::runtime_error(ss.str()); } // Return an absolute value of a possibly relative config variable.