diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index ae8aec1bd3..7ec2b59ca0 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -5381,13 +5381,15 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool bool process_multi_extruder = false; std::vector filament_variant_index; size_t extruder_variant_count; - if (!config.option("filament_self_index")) { - std::vector& filament_self_indice = config.option("filament_self_index", true)->values; + // A config loaded over the full defaults has a one-entry index even when the file has none. + ConfigOptionInts* filament_self_index_opt = config.option("filament_self_index", true); + if (filament_self_index_opt->size() < num_filaments) { + std::vector& filament_self_indice = filament_self_index_opt->values; filament_self_indice.resize(num_filaments); for (int index = 0; index < num_filaments; index++) filament_self_indice[index] = index + 1; } - std::vector filament_self_indice = std::move(config.option("filament_self_index")->values); + std::vector filament_self_indice = std::move(filament_self_index_opt->values); // ORCA: Initialize filament_extruder_variant for backward compatibility with old 3mf files // that don't have this option saved or have it with default single-element value ConfigOptionStrings* filament_extruder_variant_opt = config.option("filament_extruder_variant"); diff --git a/tests/libslic3r/test_preset_bundle_loading.cpp b/tests/libslic3r/test_preset_bundle_loading.cpp index e1ae29b473..50d368763d 100644 --- a/tests/libslic3r/test_preset_bundle_loading.cpp +++ b/tests/libslic3r/test_preset_bundle_loading.cpp @@ -5888,6 +5888,21 @@ TEST_CASE("A project saved with pressure advance per filament applies it to ever check_double_vector(petg.opt("filament_flow_ratio")->values, { 0.97 }); } +TEST_CASE("A multi-toolhead project saved without filament self indices loads every filament", "[Preset][Bundle]") +{ + const std::vector colors = { "#FF0000", "#000000", "#FFFFFF", "#FFFF00" }; + DynamicPrintConfig config = DynamicPrintConfig::full_print_config(); + config.opt("filament_colour")->values = colors; + config.opt("nozzle_diameter")->values = std::vector(colors.size(), 0.4); + config.option("single_extruder_multi_material")->value = false; + Preset::normalize(config); + + PresetBundle bundle; + REQUIRE_NOTHROW(bundle.load_config_model("test.3mf", std::move(config))); + CHECK(bundle.filament_presets.size() == colors.size()); + CHECK(bundle.project_config.opt("filament_colour")->values == colors); +} + TEST_CASE("A system preset resolves by name from the bundled profiles", "[Preset][Bundle]") { ScopedTemporaryDir temp_dir;