Guard the lookup of the printed layer count

ToolOrdering::tools_for_layer() only asserts that the Z it is given is
in the tool ordering, so a release build would read past its end if
the layer lists ever disagreed. A layer the tool ordering doesn't hold
is now counted, as every layer was before. The comment now says what
the count leaves out.
This commit is contained in:
Ian Bassi committed 2026-11-30 14:27:08 -03:00
1 parent fbb75de586
commit 19982a5923
1 file changed
+9 -2
+9 -2
View File
@@ -3508,7 +3508,8 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
// object's empty lead-in), so they must not be counted here either or the layer
// count in the file disagrees with its layer changes.
const bool belt = print.config().belt_printer.value;
// Elsewhere process_layer() skips a layer its tool ordering gives no extruder, such as a tip too thin to print.
// Counts the print_z that process_layer() prints. It skips a layer whose tool ordering has no extruder, such as
// the tip of a cone too thin for a wall.
const auto count_printed_layers = [belt](const auto &objects, const ToolOrdering &tool_ordering) {
std::vector<coordf_t> zs;
for (const PrintObject *object : objects) {
@@ -3525,7 +3526,13 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
}
if (! belt)
zs.erase(std::remove_if(zs.begin(), zs.end(), [&tool_ordering](coordf_t z) {
return tool_ordering.empty() || tool_ordering.tools_for_layer(z).extruders.empty();
if (tool_ordering.empty())
return true;
// The lookup only asserts that z is in the tool ordering. A layer that is not is counted.
if (z > (tool_ordering.end() - 1)->print_z + EPSILON)
return false;
const LayerTools &layer_tools = tool_ordering.tools_for_layer(z);
return std::abs(layer_tools.print_z - z) < EPSILON && layer_tools.extruders.empty();
}),
zs.end());
if (zs.empty())