Mods making slic3r runnable from commandline without crashing (Pshemek)

This commit is contained in:
Pshemek 2019-04-03 15:20:37 +00:00 committed by Joseph Lenox
parent daaceff20a
commit 1db87ed41a
4 changed files with 48 additions and 13 deletions

View File

@ -11,6 +11,7 @@ option(COVERAGE "Build with gcov code coverage profiling." OFF)
# only on newer GCCs: -ftemplate-backtrace-limit=0 # 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_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) if (MSVC)
add_compile_options(-W3) add_compile_options(-W3)

View File

@ -36,7 +36,7 @@ int CLI::run(int argc, char **argv) {
// Convert arguments to UTF-8 (needed on Windows). // Convert arguments to UTF-8 (needed on Windows).
// argv then points to memory owned by a. // argv then points to memory owned by a.
boost::nowide::args a(argc, argv); boost::nowide::args a(argc, argv);
std::cerr<<"after boost::nowide<<args"<<std::endl;
// parse all command line options into a DynamicConfig // parse all command line options into a DynamicConfig
t_config_option_keys opt_order; t_config_option_keys opt_order;
this->config_def.merge(cli_actions_config_def); this->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(cli_misc_config_def);
this->config_def.merge(print_config_def); this->config_def.merge(print_config_def);
this->config.def = &this->config_def; this->config.def = &this->config_def;
std::cerr<<"after merges"<<std::endl;
// if any option is unsupported, print usage and abort immediately // if any option is unsupported, print usage and abort immediately
if (!this->config.read_cli(argc, argv, &this->input_files, &opt_order)) { if (!this->config.read_cli(argc, argv, &this->input_files, &opt_order)) {
this->print_help(); this->print_help();
return 1; return 1;
} }
// parse actions and transform options // parse actions and transform options
for (auto const &opt_key : opt_order) { for (auto const &opt_key : opt_order) {
if (cli_actions_config_def.has(opt_key)) this->actions.push_back(opt_key); 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); if (cli_transform_config_def.has(opt_key)) this->transforms.push_back(opt_key);
} }
try{
// load config files supplied via --load // load config files supplied via --load
for (auto const &file : config.getStrings("load")) { for (auto const &file : config.getStrings("load")) {
if (!boost::filesystem::exists(file)) { if (!boost::filesystem::exists(file)) {
@ -78,15 +77,18 @@ int CLI::run(int argc, char **argv) {
c.normalize(); c.normalize();
this->print_config.apply(c); this->print_config.apply(c);
} }
}catch (...){
std::cerr<<"Exception in 'load' processing "<<std::endl;
}
// apply command line options to a more specific DynamicPrintConfig which provides normalize() // apply command line options to a more specific DynamicPrintConfig which provides normalize()
// (command line options override --load files) // (command line options override --load files)
this->print_config.apply(config, true); this->print_config.apply(config, true);
this->print_config.normalize(); this->print_config.normalize();
std::cerr<<"after config normalize" << std::endl;
// create a static (full) print config to be used in our logic // create a static (full) print config to be used in our logic
this->full_print_config.apply(this->print_config); this->full_print_config.apply(this->print_config);
std::cerr<<"apply full config"<<std::endl;
// validate config // validate config
try { try {
this->full_print_config.validate(); this->full_print_config.validate();
@ -94,6 +96,7 @@ int CLI::run(int argc, char **argv) {
boost::nowide::cerr << e.what() << std::endl; boost::nowide::cerr << e.what() << std::endl;
return 1; return 1;
} }
std::cerr<<"after config validation"<<std::endl;
// read input file(s) if any // read input file(s) if any
for (auto const &file : input_files) { for (auto const &file : input_files) {

View File

@ -372,6 +372,7 @@ void
ConfigBase::apply_only(const ConfigBase &other, const t_config_option_keys &opt_keys, bool ignore_nonexistent, bool default_nonexistent) { ConfigBase::apply_only(const ConfigBase &other, const t_config_option_keys &opt_keys, bool ignore_nonexistent, bool default_nonexistent) {
// loop through options and apply them // loop through options and apply them
for (const t_config_option_key &opt_key : opt_keys) { for (const t_config_option_key &opt_key : opt_keys) {
try{
ConfigOption* my_opt = this->option(opt_key, true); ConfigOption* my_opt = this->option(opt_key, true);
if (opt_key.size() == 0) continue; if (opt_key.size() == 0) continue;
if (my_opt == NULL) { 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; std::string error = "Unexpected failure when deserializing serialized value for " + opt_key;
CONFESS(error.c_str()); CONFESS(error.c_str());
} }
} catch ( UnknownOptionException & e ){
// std::cerr<<e.what()<<std::endl;
}
} }
} }

View File

@ -1,6 +1,10 @@
#ifndef slic3r_ConfigBase_hpp_ #ifndef slic3r_ConfigBase_hpp_
#define slic3r_ConfigBase_hpp_ #define slic3r_ConfigBase_hpp_
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
#include <map> #include <map>
#include <climits> #include <climits>
#include <cstdio> #include <cstdio>
@ -15,6 +19,8 @@
#include "Point.hpp" #include "Point.hpp"
#include "Geometry.hpp" #include "Geometry.hpp"
namespace Slic3r { namespace Slic3r {
/// Name of the configuration option. /// Name of the configuration option.
@ -31,20 +37,40 @@ class ConfigOptionException : public std::exception {
public: public:
const t_config_option_key opt_key; const t_config_option_key opt_key;
ConfigOptionException(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<<strings[i]<<std::endl;
free (strings);
//*/
};
virtual const char* what() const noexcept {
std::string s("Exception with the option: ");
s += this->opt_key;
return s.c_str();
}
}; };
class UnknownOptionException : public ConfigOptionException { class UnknownOptionException : public ConfigOptionException {
using ConfigOptionException::ConfigOptionException; using ConfigOptionException::ConfigOptionException;
}; };
class InvalidOptionException : public ConfigOptionException { class InvalidOptionException : public ConfigOptionException {
using ConfigOptionException::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. /// Specialization of std::exception to indicate that an unsupported accessor was called on a config option.