fix(engine): publish the nozzle group result for sequential prints

The Print-level LayeredNozzleGroupResult had a single producer, the
by-layer branch of ToolOrdering, which is gated to non-sequential prints.
The by-object branch in Print::process computed a grouping only in auto
map modes and never stored it, so a sequential slice exported with a null
group result: the per-nozzle placeholder tables came up empty and any
start g-code indexing nozzle_diameter_at_nozzle_id[] aborted with
"Indexing an empty vector variable". A prior by-layer slice masked the
bug by leaving its (never cleared) result on the Print.

Now the by-object branch runs get_recommended_filament_maps in every
static map mode (in manual modes the result mirrors the user's
assignment, deviations throw as in by-layer) and publishes it
print-wide. The config write-back stays gated to auto modes: in manual
modes it would only re-store the pre-slice values.

Regression test: a two-object by-object print must publish a non-null
group result and resolve nozzle_diameter_at_nozzle_id[] in start g-code
(both fail without the fix). Suites green (libslic3r 48929/162,
fff_print 633/60); 18-fixture byte gate identical; the by-object repro
project goes from the export error to valid g-code, determinism x2.
This commit is contained in:
SoftFever
2026-07-12 00:46:15 +08:00
parent c65b0540a3
commit 780b2f1ebe
4 changed files with 36 additions and 9 deletions

View File

@@ -8473,8 +8473,8 @@ std::string GCode::retract(bool toolchange, bool is_last_retraction, LiftType li
void GCode::update_layer_related_config(int layer_id){
auto group_result = m_print->get_layered_nozzle_group_result();
// Orca: sequential (by-object) prints never publish a Print-level layered group result on
// this branch; the statically applied config maps stay authoritative there.
// Orca: defensive — with no published group result the statically applied config maps stay
// authoritative.
if(!group_result)
return;

View File

@@ -2116,7 +2116,8 @@ void ToolOrdering::reorder_extruders_for_minimum_flush_volume(bool reorder_first
{
// Orca: the ToolOrdering member is stored unconditionally, but the Print-level store is gated
// behind a not-sequential check. There is no is_sequential_print() here, so it is mirrored
// with the same predicate the branch above uses.
// with the same predicate the branch above uses. Sequential prints publish their result
// from the by-object branch in Print::process instead.
const bool not_sequential = print_config->print_sequence != PrintSequence::ByObject ||
(m_print && m_print->objects().size() == 1);
if (m_print != nullptr && not_sequential)

View File

@@ -2511,15 +2511,19 @@ void Print::process(long long *time_cost_with_cache, bool use_cache)
auto filament_unprintable_volumes = this->get_filament_unprintable_flow(used_filaments);
std::vector<int>filament_maps = this->get_filament_maps();
auto map_mode = get_filament_map_mode();
// get recommended filament map
// Grouping returns a nozzle-aware result; the 1-based extruder map for the by-object
// path is derived from it. It is computed in every static map mode (in manual modes it
// mirrors the user's assignment) and published print-wide: GCode's per-nozzle
// placeholder and config-index lookups read it via get_layered_nozzle_group_result(),
// and without it sequential exports on multi-nozzle printers see an empty nozzle table
// (e.g. nozzle_diameter_at_nozzle_id[]) and custom g-code fails to resolve.
auto grouping_result = ToolOrdering::get_recommended_filament_maps(all_filaments, this, map_mode, physical_unprintables, geometric_unprintables, filament_unprintable_volumes);
this->set_nozzle_group_result(std::make_shared<MultiNozzleUtils::LayeredNozzleGroupResult>(grouping_result));
// Orca: the sequential write-back stays gated to auto modes. In manual modes the
// config maps already carry the user's assignment (the per-object ToolOrdering below
// consumes them directly), so a write-back would only re-store the pre-slice values;
// keeping the gate avoids churning the config on every sequential manual slice.
if (map_mode < FilamentMapMode::fmmManual) {
// Grouping returns a nozzle-aware result; the 1-based extruder map
// for the by-object path is derived from it.
auto grouping_result = ToolOrdering::get_recommended_filament_maps(all_filaments, this, map_mode, physical_unprintables, geometric_unprintables, filament_unprintable_volumes);
auto derived_maps = grouping_result.get_extruder_map(false);
if (!derived_maps.empty()) {
filament_maps = derived_maps;
@@ -3532,8 +3536,8 @@ int Print::get_nozzle_config_index(int filament_id, int layer_id)
int Print::get_config_index(int filament_id, int layer_id, const std::vector<std::string> &variant_list, const std::vector<int>& self_index_list, FilamentIndexMap &index_map)
{
auto group_result = get_layered_nozzle_group_result();
// Orca: sequential (by-object) prints never publish a Print-level layered group result on this
// branch, so fall back to the static identity: one filament-variant column per filament.
// Orca: defensive — when no grouping producer has published a result yet, fall back to the
// static identity: one filament-variant column per filament.
if (!group_result)
return filament_id;
auto nozzle_info = group_result->get_nozzle_for_filament(filament_id, layer_id);