From 1db87ed41a27b467719e6f0aa054b0f626ff17fd Mon Sep 17 00:00:00 2001 From: Pshemek Date: Wed, 3 Apr 2019 15:20:37 +0000 Subject: [PATCH] Mods making slic3r runnable from commandline without crashing (Pshemek) --- src/CMakeLists.txt | 1 + src/slic3r.cpp | 15 ++++++++----- xs/src/libslic3r/ConfigBase.cpp | 5 +++++ xs/src/libslic3r/ConfigBase.hpp | 40 +++++++++++++++++++++++++++------ 4 files changed, 48 insertions(+), 13 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b4d2d7de0..e91dbc864 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,6 +11,7 @@ option(COVERAGE "Build with gcov code coverage profiling." OFF) # only on newer GCCs: -ftemplate-backtrace-limit=0 add_compile_options(-DNO_PERL -DM_PI=3.14159265358979323846 -D_GLIBCXX_USE_C99 -DHAS_BOOL -DNOGDI -DBOOST_ASIO_DISABLE_KQUEUE) +#add_link_options(-rdynamic) if (MSVC) add_compile_options(-W3) diff --git a/src/slic3r.cpp b/src/slic3r.cpp index b9680ae03..3df317196 100644 --- a/src/slic3r.cpp +++ b/src/slic3r.cpp @@ -36,7 +36,7 @@ int CLI::run(int argc, char **argv) { // Convert arguments to UTF-8 (needed on Windows). // argv then points to memory owned by a. boost::nowide::args a(argc, argv); - + std::cerr<<"after boost::nowide<config_def.merge(cli_actions_config_def); @@ -44,19 +44,18 @@ int CLI::run(int argc, char **argv) { this->config_def.merge(cli_misc_config_def); this->config_def.merge(print_config_def); this->config.def = &this->config_def; - + std::cerr<<"after merges"<config.read_cli(argc, argv, &this->input_files, &opt_order)) { this->print_help(); return 1; } - // parse actions and transform options for (auto const &opt_key : opt_order) { if (cli_actions_config_def.has(opt_key)) this->actions.push_back(opt_key); if (cli_transform_config_def.has(opt_key)) this->transforms.push_back(opt_key); } - + try{ // load config files supplied via --load for (auto const &file : config.getStrings("load")) { if (!boost::filesystem::exists(file)) { @@ -78,15 +77,18 @@ int CLI::run(int argc, char **argv) { c.normalize(); this->print_config.apply(c); } + }catch (...){ + std::cerr<<"Exception in 'load' processing "<print_config.apply(config, true); this->print_config.normalize(); - + std::cerr<<"after config normalize" << std::endl; // create a static (full) print config to be used in our logic this->full_print_config.apply(this->print_config); - + std::cerr<<"apply full config"<full_print_config.validate(); @@ -94,6 +96,7 @@ int CLI::run(int argc, char **argv) { boost::nowide::cerr << e.what() << std::endl; return 1; } + std::cerr<<"after config validation"<option(opt_key, true); if (opt_key.size() == 0) continue; if (my_opt == NULL) { @@ -395,6 +396,10 @@ ConfigBase::apply_only(const ConfigBase &other, const t_config_option_keys &opt_ std::string error = "Unexpected failure when deserializing serialized value for " + opt_key; CONFESS(error.c_str()); } + } catch ( UnknownOptionException & e ){ + + // std::cerr< +#include +#include + #include #include #include @@ -15,6 +19,8 @@ #include "Point.hpp" #include "Geometry.hpp" + + namespace Slic3r { /// Name of the configuration option. @@ -31,20 +37,40 @@ class ConfigOptionException : public std::exception { public: const t_config_option_key opt_key; ConfigOptionException(const t_config_option_key _opt_key) - : opt_key(_opt_key) {}; + : opt_key(_opt_key) { + /* + void *array[10]; + size_t size; + char **strings; + size_t i; + + size = backtrace (array, 10); + strings = backtrace_symbols (array, size); + + printf ("Obtained %zd stack frames.\n", size); + + for (i = 0; i < size; i++) + std::cerr<opt_key; + return s.c_str(); + } + }; class UnknownOptionException : public ConfigOptionException { using ConfigOptionException::ConfigOptionException; + }; class InvalidOptionException : public ConfigOptionException { using ConfigOptionException::ConfigOptionException; - public: - virtual const char* what() const noexcept { - std::string s("Invalid value for option: "); - s += this->opt_key; - return s.c_str(); - } + }; /// Specialization of std::exception to indicate that an unsupported accessor was called on a config option.