From 9b2fcaa53af870b14e1b7a031c2c68749a1b5478 Mon Sep 17 00:00:00 2001 From: Kris Austin Date: Fri, 16 Oct 2026 18:12:24 -0500 Subject: [PATCH] fix: "bad allocation" when opening a 2.4 project with a custom filament (#16569) --- src/libslic3r/Preset.cpp | 1 + .../libslic3r/test_preset_bundle_loading.cpp | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index f557348998..4ae928cc95 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -2293,6 +2293,7 @@ void PresetCollection::load_project_embedded_presets(std::vector& proje BOOST_LOG_TRIVIAL(error) << boost::format("can not find parent for config %1%!")%preset->file; continue; } + extend_default_config_length(config, false, {}); preset->config.update_diff_values_to_child_config(config, extruder_id_name, extruder_variant_name, *key_set1, *key_set2); //preset->config.apply(std::move(config)); Preset::normalize(preset->config); diff --git a/tests/libslic3r/test_preset_bundle_loading.cpp b/tests/libslic3r/test_preset_bundle_loading.cpp index 47f5c80cca..7ea1452042 100644 --- a/tests/libslic3r/test_preset_bundle_loading.cpp +++ b/tests/libslic3r/test_preset_bundle_loading.cpp @@ -985,6 +985,37 @@ TEST_CASE("A user filament synced to the cloud and back keeps its values and uns } } +TEST_CASE("A project filament storing one value for a per-variant key applies it to every variant", "[Preset][Bundle][Regression]") +{ + PresetCollection filaments(Preset::TYPE_FILAMENT, Preset::filament_options(), + static_cast(FullPrintConfig::defaults())); + Preset &parent = add_inmemory_preset(filaments, "Parent Filament"); + parent.config.set_key_value("filament_extruder_variant", new ConfigOptionStrings({"Direct Drive Standard", "Direct Drive High Flow"})); + parent.config.set_key_value("adaptive_pressure_advance_model", new ConfigOptionStrings({"parent standard", "parent high flow"})); + parent.config.set_deserialize_strict("pressure_advance", "0.02,0.03"); + parent.is_system = true; + + // A filament saved before these keys became per-variant lists both variants but stores each key once. + const std::string model = "0.025,15.6,5000"; + DynamicPrintConfig config; + config.set_key_value(BBL_JSON_KEY_INHERITS, new ConfigOptionString("Parent Filament")); + config.set_key_value("filament_extruder_variant", new ConfigOptionStrings({"Direct Drive Standard", "Direct Drive High Flow"})); + config.set_key_value("adaptive_pressure_advance_model", new ConfigOptionStrings({model})); + config.set_deserialize_strict("pressure_advance", "0.016"); + auto embedded = std::make_unique(Preset::TYPE_FILAMENT, "Project Filament", false); + embedded->config = std::move(config); + embedded->is_project_embedded = true; + + std::vector project_presets{embedded.get()}; + PresetsConfigSubstitutions substitutions; + filaments.load_project_embedded_presets(project_presets, PRESET_FILAMENT_NAME, substitutions, ForwardCompatibilitySubstitutionRule::Disable); + + const Preset *loaded = filaments.find_preset("Project Filament"); + REQUIRE(loaded != nullptr); + CHECK(loaded->config.option("adaptive_pressure_advance_model")->values == std::vector{model, model}); + check_double_vector(loaded->config.option("pressure_advance")->values, {0.016, 0.016}); +} + TEST_CASE("Repeated loads of a user preset directory produce the same presets", "[Preset][Bundle]") { ScopedTemporaryDir temp_dir;