diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index 026a96dc29..5a23d8b8be 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -5568,7 +5568,8 @@ DynamicPrintConfig PresetBundle::full_fff_config(bool apply_extruder, std::optio out.apply(this->project_config); // BBS - size_t num_filaments = this->filament_presets.size(); + // Before the presets load, filament_presets is empty; that bundle has one filament, the edited preset. + size_t num_filaments = std::max(this->filament_presets.size(), 1); std::vector filament_maps = out.option("filament_map")->values; std::vector filament_volume_maps(num_filaments, (int)nvtStandard); @@ -5655,7 +5656,7 @@ DynamicPrintConfig PresetBundle::full_fff_config(bool apply_extruder, std::optio compatible_prints_condition .emplace_back(this->filaments.get_edited_preset().compatible_prints_condition()); //BBS: add logic for settings check between different system presets //std::string filament_inherits = this->filaments.get_edited_preset().inherits(); - std::string current_preset_name = this->filament_presets[0]; + std::string current_preset_name = this->filament_presets.empty() ? this->filaments.get_edited_preset().name : this->filament_presets[0]; const Preset* preset = this->filaments.find_preset(current_preset_name, true); std::string filament_inherits = preset->inherits(); inherits .emplace_back(filament_inherits); diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index f7bfc420ae..72feb2c0f8 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -3624,10 +3624,8 @@ bool GUI_App::on_init_inner() wxYield(); } - // Initialize plugins after network then register on_load callbacks so once the plugin loads finish, it gets registered automatically. - // initialize() also installs the libslic3r hooks (capability resolver, - // slicing-pipeline dispatcher) via plugin_hooks::install() -- no - // per-capability wiring belongs here. + // initialize() installs the libslic3r hooks (capability resolver, slicing-pipeline dispatcher) + // through plugin_hooks::install(), so per-capability wiring does not belong here. PluginManager& plugin_mgr = PluginManager::instance(); plugin_mgr.initialize(); @@ -3645,13 +3643,6 @@ bool GUI_App::on_init_inner() // Subscribe to the plugin loader and enumerate current actions (UI thread, once). m_action_registry->init(); - for (const std::string& plugin_key : plugin_mgr.get_enabled_plugin_keys()) { - if (!plugin_mgr.is_plugin_loaded(plugin_key)) { - plugin_mgr.load_plugin(plugin_key, false); - BOOST_LOG_TRIVIAL(info) << "Auto-loading plugin on startup: " << plugin_key; - } - } - copy_network_if_available(); on_init_network(); @@ -3805,6 +3796,15 @@ bool GUI_App::on_init_inner() plater_->get_partplate_list().set_filament_count(preset_bundle->filament_presets.size()); } + // Plugin code runs on the load thread and may read the presets, so start the loads only once + // the presets are loaded and selected. + for (const std::string& plugin_key : plugin_mgr.get_enabled_plugin_keys()) { + if (!plugin_mgr.is_plugin_loaded(plugin_key)) { + plugin_mgr.load_plugin(plugin_key, false); + BOOST_LOG_TRIVIAL(info) << "Auto-loading plugin on startup: " << plugin_key; + } + } + // BBS: #ifdef __WINDOWS__ mainframe->topbar()->SaveNormalRect(); diff --git a/tests/libslic3r/test_preset_bundle_loading.cpp b/tests/libslic3r/test_preset_bundle_loading.cpp index f3e511b8bd..bd53e876bd 100644 --- a/tests/libslic3r/test_preset_bundle_loading.cpp +++ b/tests/libslic3r/test_preset_bundle_loading.cpp @@ -392,6 +392,18 @@ TEST_CASE("Printer extruder count tolerates missing nozzle diameter", "[Preset][ CHECK(bundle.get_printer_extruder_count() == 2); } +TEST_CASE("A preset bundle builds its full config before its presets load", "[Preset][Bundle][Regression]") +{ + PresetBundle bundle; + REQUIRE(bundle.filament_presets.empty()); + bundle.filaments.get_edited_preset().config.set_key_value("filament_type", new ConfigOptionStrings({ "PETG" })); + + const DynamicPrintConfig config = bundle.full_config(); + + REQUIRE(config.has("filament_type")); + CHECK(config.option("filament_type")->values == std::vector{ "PETG" }); +} + // A per-variant key that no profile in the chain sets keeps the length of the one-nozzle root. The // inherited printer must still have a value for every variant in its own variant list. TEST_CASE("An inherited printer's per-variant values cover every variant it lists", "[Preset][Bundle][Regression]")