diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index c79d7f5541..d4aee4b0ed 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -19,6 +19,8 @@ #include #include #include +#include +#include #if __has_include() #include @@ -4061,19 +4063,23 @@ void GCodeProcessor::process_T(const GCodeReader::GCodeLine& line) void GCodeProcessor::process_T(const std::string_view command) { + unsigned int new_extruder = 0; + auto ret = std::from_chars(command.data() + 1, command.data()+command.size(), new_extruder); + if (std::errc::invalid_argument == ret.ec) + return; + if (command.length() > 1) { - int eid = 0; - if (! parse_number(command.substr(1), eid) || eid < 0 || eid > 254) { + if (new_extruder < 0 || new_extruder > 254) { //BBS: T255, T1000 and T1100 is used as special command for BBL machine and does not cost time. return directly if ((m_flavor == gcfMarlinLegacy || m_flavor == gcfMarlinFirmware) && (command == "Tx" || command == "Tc" || command == "T?" || - eid == 1000 || eid == 1100 || eid == 255)) + new_extruder == 1000 || new_extruder == 1100 || new_extruder == 255)) return; // T-1 is a valid gcode line for RepRap Firmwares (used to deselects all tools) - if ((m_flavor != gcfRepRapFirmware && m_flavor != gcfRepRapSprinter) || eid != -1) + if ((m_flavor != gcfRepRapFirmware && m_flavor != gcfRepRapSprinter) || new_extruder != -1) BOOST_LOG_TRIVIAL(error) << "Invalid T command (" << command << ")."; } else { - unsigned char id = static_cast(eid); + unsigned char id = static_cast(new_extruder); if (m_extruder_id != id) { if (id >= m_result.extruders_count) BOOST_LOG_TRIVIAL(error) << "Invalid T command (" << command << ").";