Follow-up of 573194e059 -> Fixed crash when opening a gcode file

This commit is contained in:
enricoturri1966 2020-09-07 11:30:31 +02:00
parent 014a90b51b
commit 8579184d70
2 changed files with 9 additions and 6 deletions

View File

@ -759,14 +759,17 @@ void GCodeProcessor::process_file(const std::string& filename, std::function<voi
// process gcode
m_result.id = ++s_result_id;
// 1st move must be a dummy move
m_result.moves.emplace_back(MoveVertex());
m_parser.parse_file(filename, [this, cancel_callback, &last_cancel_callback_time](GCodeReader& reader, const GCodeReader::GCodeLine& line) {
auto curr_time = std::chrono::high_resolution_clock::now();
if (cancel_callback != nullptr) {
// call the cancel callback every 100 ms
auto curr_time = std::chrono::high_resolution_clock::now();
if (std::chrono::duration_cast<std::chrono::milliseconds>(curr_time - last_cancel_callback_time).count() > 100) {
cancel_callback();
last_cancel_callback_time = curr_time;
}
}
process_gcode_line(line);
});

View File

@ -420,7 +420,7 @@ namespace Slic3r {
// Process the gcode contained in the file with the given filename
// throws CanceledException through print->throw_if_canceled() (sent by the caller as callback).
void process_file(const std::string& filename, std::function<void()> cancel_callback = std::function<void()>());
void process_file(const std::string& filename, std::function<void()> cancel_callback = nullptr);
float get_time(PrintEstimatedTimeStatistics::ETimeMode mode) const;
std::string get_time_dhm(PrintEstimatedTimeStatistics::ETimeMode mode) const;