Load startup plugins after the presets are loaded (#17873)

* Load startup plugins after the presets are loaded

The startup plugin loads ran on the load thread while the main thread
was still starting the network and had not loaded the presets yet. A
plugin that reads the presets while it registers, such as through
full_config_value(), reached PresetBundle::full_fff_config() while
filament_presets was still empty and crashed reading filament_presets[0].
A plugin that got there a little later read the presets while
load_presets() was rebuilding them.

Start the startup loads after load_current_presets(). A printer agent
that a plugin registers after that point is already installed by the
late registration path.

Fixes #17792

* Build the full config of a bundle whose presets are not loaded yet

A new PresetBundle has no filament_presets until load_presets() runs,
and full_fff_config() read filament_presets[0] anyway, which crashed any
caller that asked for the full config before the presets loaded. Treat
such a bundle as having one filament, the edited filament preset.
This commit is contained in:
Kris Austin authored and GitHub committed 2026-11-25 14:18:45 +08:00
1 parent ce7f703e68
commit 71a1f4f6f2
3 files changed
+26 -13

No files matched your search

+3 -2
View File
@@ -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<size_t>(this->filament_presets.size(), 1);
std::vector<int> filament_maps = out.option<ConfigOptionInts>("filament_map")->values;
std::vector<int> 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);
+11 -11
View File
@@ -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();
@@ -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<ConfigOptionStrings>("filament_type")->values == std::vector<std::string>{ "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]")