From 8579184d70568d2850125c557a6d35b2551a49e6 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 7 Sep 2020 11:30:31 +0200 Subject: [PATCH] Follow-up of 573194e059836916b6f216dc068c27a89ea7b843 -> Fixed crash when opening a gcode file --- src/libslic3r/GCode/GCodeProcessor.cpp | 13 ++++++++----- src/libslic3r/GCode/GCodeProcessor.hpp | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index 13764f11e..e9264dbd4 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -759,13 +759,16 @@ void GCodeProcessor::process_file(const std::string& filename, std::function(curr_time - last_cancel_callback_time).count() > 100) { - cancel_callback(); - last_cancel_callback_time = curr_time; + 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(curr_time - last_cancel_callback_time).count() > 100) { + cancel_callback(); + last_cancel_callback_time = curr_time; + } } process_gcode_line(line); }); diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index 42772d12b..b31591ca8 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -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 cancel_callback = std::function()); + void process_file(const std::string& filename, std::function cancel_callback = nullptr); float get_time(PrintEstimatedTimeStatistics::ETimeMode mode) const; std::string get_time_dhm(PrintEstimatedTimeStatistics::ETimeMode mode) const;