Skip to content

Commit

Permalink
Mods making slic3r runnable from commandline without crashing (Pshemek)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pshemek authored and lordofhyphens committed Apr 13, 2019
1 parent daaceff commit 1db87ed
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 9 additions & 6 deletions src/slic3r.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,26 @@ 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<<args"<<std::endl;
// parse all command line options into a DynamicConfig
t_config_option_keys opt_order;
this->config_def.merge(cli_actions_config_def);
this->config_def.merge(cli_transform_config_def);
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"<<std::endl;
// if any option is unsupported, print usage and abort immediately
if (!this->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)) {
Expand All @@ -78,22 +77,26 @@ int CLI::run(int argc, char **argv) {
c.normalize();
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()
// (command line options override --load files)
this->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"<<std::endl;
// validate config
try {
this->full_print_config.validate();
} catch (InvalidOptionException &e) {
boost::nowide::cerr << e.what() << std::endl;
return 1;
}
std::cerr<<"after config validation"<<std::endl;

// read input file(s) if any
for (auto const &file : input_files) {
Expand Down
5 changes: 5 additions & 0 deletions xs/src/libslic3r/ConfigBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ void
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
for (const t_config_option_key &opt_key : opt_keys) {
try{
ConfigOption* my_opt = this->option(opt_key, true);
if (opt_key.size() == 0) continue;
if (my_opt == NULL) {
Expand All @@ -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<<e.what()<<std::endl;
}
}
}

Expand Down
40 changes: 33 additions & 7 deletions xs/src/libslic3r/ConfigBase.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef slic3r_ConfigBase_hpp_
#define slic3r_ConfigBase_hpp_

#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>

#include <map>
#include <climits>
#include <cstdio>
Expand All @@ -15,6 +19,8 @@
#include "Point.hpp"
#include "Geometry.hpp"



namespace Slic3r {

/// Name of the configuration option.
Expand All @@ -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<<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 {
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.
Expand Down

0 comments on commit 1db87ed

Please sign in to comment.