Fix of a possible locales mismatch during GCode export

There is a mysterious issue with GCode annotations printed with decimal
commas instead of points. tbb threads should be set to "C" locales when started,
either another thread is spawned by tbb, or someone switches the thread locales
and leaves it in the pool.
This commit is contained in:
Lukas Matena 2022-01-24 13:08:00 +01:00
parent 18be6a9395
commit cb99d491af

View File

@ -2129,13 +2129,13 @@ GCode::LayerResult GCode::process_layer(
// add tag for processor // add tag for processor
gcode += ";" + GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Layer_Change) + "\n"; gcode += ";" + GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Layer_Change) + "\n";
// export layer z // export layer z
char buf[64]; gcode += std::string(";Z:") + float_to_string_decimal_point(print_z) + "\n";
sprintf(buf, ";Z:%g\n", print_z);
gcode += buf;
// export layer height // export layer height
float height = first_layer ? static_cast<float>(print_z) : static_cast<float>(print_z) - m_last_layer_z; float height = first_layer ? static_cast<float>(print_z) : static_cast<float>(print_z) - m_last_layer_z;
sprintf(buf, ";%s%g\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Height).c_str(), height); gcode += std::string(";") + GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Height)
gcode += buf; + float_to_string_decimal_point(height) + "\n";
// update caches // update caches
m_last_layer_z = static_cast<float>(print_z); m_last_layer_z = static_cast<float>(print_z);
m_max_layer_z = std::max(m_max_layer_z, m_last_layer_z); m_max_layer_z = std::max(m_max_layer_z, m_last_layer_z);
@ -3002,33 +3002,34 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description,
// PrusaMultiMaterial::Writer may generate GCodeProcessor::Height_Tag lines without updating m_last_height // PrusaMultiMaterial::Writer may generate GCodeProcessor::Height_Tag lines without updating m_last_height
// so, if the last role was erWipeTower we force export of GCodeProcessor::Height_Tag lines // so, if the last role was erWipeTower we force export of GCodeProcessor::Height_Tag lines
bool last_was_wipe_tower = (m_last_processor_extrusion_role == erWipeTower); bool last_was_wipe_tower = (m_last_processor_extrusion_role == erWipeTower);
char buf[64];
assert(is_decimal_separator_point()); assert(is_decimal_separator_point());
if (path.role() != m_last_processor_extrusion_role) { if (path.role() != m_last_processor_extrusion_role) {
m_last_processor_extrusion_role = path.role(); m_last_processor_extrusion_role = path.role();
char buf[64];
sprintf(buf, ";%s%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Role).c_str(), ExtrusionEntity::role_to_string(m_last_processor_extrusion_role).c_str()); sprintf(buf, ";%s%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Role).c_str(), ExtrusionEntity::role_to_string(m_last_processor_extrusion_role).c_str());
gcode += buf; gcode += buf;
} }
if (last_was_wipe_tower || m_last_width != path.width) { if (last_was_wipe_tower || m_last_width != path.width) {
m_last_width = path.width; m_last_width = path.width;
sprintf(buf, ";%s%g\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Width).c_str(), m_last_width); gcode += std::string(";") + GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Width)
gcode += buf; + float_to_string_decimal_point(m_last_width) + "\n";
} }
#if ENABLE_GCODE_VIEWER_DATA_CHECKING #if ENABLE_GCODE_VIEWER_DATA_CHECKING
if (last_was_wipe_tower || (m_last_mm3_per_mm != path.mm3_per_mm)) { if (last_was_wipe_tower || (m_last_mm3_per_mm != path.mm3_per_mm)) {
m_last_mm3_per_mm = path.mm3_per_mm; m_last_mm3_per_mm = path.mm3_per_mm;
sprintf(buf, ";%s%f\n", GCodeProcessor::Mm3_Per_Mm_Tag.c_str(), m_last_mm3_per_mm); gcode += std::string(";") + GCodeProcessor::Mm3_Per_Mm_Tag
gcode += buf; + float_to_string_decimal_point(m_last_mm3_per_mm) + "\n";
} }
#endif // ENABLE_GCODE_VIEWER_DATA_CHECKING #endif // ENABLE_GCODE_VIEWER_DATA_CHECKING
if (last_was_wipe_tower || std::abs(m_last_height - path.height) > EPSILON) { if (last_was_wipe_tower || std::abs(m_last_height - path.height) > EPSILON) {
m_last_height = path.height; m_last_height = path.height;
sprintf(buf, ";%s%g\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Height).c_str(), m_last_height);
gcode += buf; gcode += std::string(";") + GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Height)
+ float_to_string_decimal_point(m_last_height) + "\n";
} }
std::string comment; std::string comment;