Start the Last Fill Role Empty So a Top-Only Lift Never Lifts the First Travel (#17949)

With Lift Z enforcement set to Top Only, a retraction lifts when the last fill was top solid infill or ironing. `m_last_notgapfill_extrusion_role` had no initial value, and the first travel of a print comes before any fill, so it read whatever was left in memory, often the previous slice's last role. Slicing the same project twice could lift the first travel one time and not the next. It now starts as `erNone`.

The new fff_print test fills new memory with the top solid infill role on glibc, so it fails without the fix on every Linux run.
This commit is contained in:
HanifKoh authored and GitHub committed 2026-11-27 17:15:01 -06:00
1 parent de3e742d3f
commit fe6da0040c
2 files changed
+49

No files matched your search

+48
View File
@@ -29,6 +29,9 @@
#include <cstddef>
#include <fstream>
#include <initializer_list>
#if defined(__GLIBC__)
#include <malloc.h>
#endif
#include <ios>
#include <regex>
#include <set>
@@ -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