From b488fdecec8acb32f384c72c2373eac5037911e0 Mon Sep 17 00:00:00 2001 From: Noisyfox Date: Wed, 22 Jan 2025 09:57:28 +0800 Subject: [PATCH] Fix issue that `TIMELAPSE_TAKE_FRAME` is recognized as tool change command (#7926) Fix issue that `TIMELAPSE_TAKE_FRAME` is recognized as tool change command and triggers preheat (SoftFever/OrcaSlicer#7842) --- src/libslic3r/GCode/GCodeProcessor.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index 6ba31ceea1..6f99ff55f4 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -4918,10 +4918,13 @@ void GCodeProcessor::run_post_process() // add lines M104 to exported gcode auto process_line_T = [this, &export_lines](const std::string& gcode_line, const size_t g1_lines_counter, const ExportLines::Backtrace& backtrace) { const std::string cmd = GCodeReader::GCodeLine::extract_cmd(gcode_line); + + int tool_number = -1; + if (!parse_number(std::string_view(cmd).substr(1), tool_number)){ + // invalid T command, such as the "TIMELAPSE_TAKE_FRAME" gcode, just ignore + return; + } if (cmd.size() >= 2) { - std::stringstream ss(cmd.substr(1)); - int tool_number = -1; - ss >> tool_number; if (tool_number != -1) { if (tool_number < 0 || (int)m_extruder_temps_config.size() <= tool_number) { // found an invalid value, clamp it to a valid one