diff --git a/src/libslic3r/GCode.hpp b/src/libslic3r/GCode.hpp index c42c9ce3d6..51b3687811 100644 --- a/src/libslic3r/GCode.hpp +++ b/src/libslic3r/GCode.hpp @@ -242,6 +242,7 @@ public: //m_volumetric_speed(0), m_last_pos_defined(false), m_last_extrusion_role(erNone), + m_last_notgapfill_extrusion_role(erNone), m_last_width(0.0f), #if ENABLE_GCODE_VIEWER_DATA_CHECKING m_last_mm3_per_mm(0.0), diff --git a/tests/fff_print/test_gcode.cpp b/tests/fff_print/test_gcode.cpp index a0417f0945..027ee72837 100644 --- a/tests/fff_print/test_gcode.cpp +++ b/tests/fff_print/test_gcode.cpp @@ -29,6 +29,9 @@ #include #include #include +#if defined(__GLIBC__) +#include +#endif #include #include #include @@ -749,6 +752,51 @@ TEST_CASE("Z hop follows the lift settings of the filament printing", "[GCode]") CHECK(last < 0.2 + EPSILON); } +// With lifts enforced on top surfaces only, nothing lifts before a top surface is printed. The +// role of the last fill decides it, and the first travel of the print comes before any fill, so +// that role must start empty rather than hold whatever was in memory. On glibc the test fills new +// memory with the byte of a top solid infill role, so a missing initial value always shows. +TEST_CASE("A lift enforced on top surfaces only never lifts before the first top surface", "[GCode]") +{ + DynamicPrintConfig config = Test::multifilament_config(1, { + {"filament_retract_lift_enforce", "Top Only"}, + {"z_hop", "0.6"}, + {"retraction_length", "1"}, + {"layer_height", "0.2"}, + {"initial_layer_print_height", "0.2"}, + }); +#if defined(__GLIBC__) + mallopt(M_PERTURB, int(erTopSolidInfill) ^ 0xff); +#endif + Print print; + Model model; + // Two objects, so the first layer travels between them with a retraction. + Test::init_print({Test::cube(20), Test::cube(20)}, print, model, config); + const std::string gcode = Test::gcode(print); +#if defined(__GLIBC__) + mallopt(M_PERTURB, 0); +#endif + + double layer_z = 0.; + size_t first_layer_lifts = 0; + std::istringstream lines(gcode); + std::string line; + const std::regex z_word(R"(\bZ([-0-9.]+))"); + while (std::getline(lines, line)) { + if (line.rfind(";Z:", 0) == 0) { + layer_z = std::stod(line.substr(3)); + continue; + } + if (layer_z <= 0. || layer_z > 0.2 + EPSILON || (line.rfind("G1 ", 0) != 0 && line.rfind("G0 ", 0) != 0)) + continue; + const std::string move = line.substr(0, line.find(';')); + std::smatch match; + first_layer_lifts += std::regex_search(move, match, z_word) && std::stod(match[1]) > layer_z + 0.3; + } + CHECK(layer_z > 0.2); // the print has more than the first layer + CHECK(first_layer_lifts == 0); +} + // A temperature tower re-targets the hotend at every layer. On a multi-tool printer that // command has to name the tool printing the tower: a bare M104 goes to whichever tool the // firmware considers active, which the first-layer M109 right before it already addresses by