Fix sidebar filament count for multi-extruder printers (#13706)

load_selections() and update_selections() size the parallel project_config
arrays (filament_colour, filament_colour_type, filament_map) off
filament_presets.size(). When the saved list is shorter than the printer's
nozzle count — never-used printer, hand-trimmed conf, or fewer filament_NN
entries than nozzles — the loaded colors get truncated and the sidebar
starts up one combo short.
This commit is contained in:
SoftFever
2026-05-18 01:18:09 +08:00
committed by GitHub
parent bcbc581417
commit 484ce81e38
2 changed files with 23 additions and 0 deletions

View File

@@ -2614,6 +2614,9 @@ void PresetBundle::update_selections(AppConfig &config)
break;
this->filament_presets.emplace_back(remove_ini_suffix(f_name));
}
update_filament_count();
std::vector<std::string> filament_colors;
auto f_colors = config.get_printer_setting(initial_printer_profile_name, "filament_colors");
if (!f_colors.empty()) {
@@ -2755,6 +2758,8 @@ void PresetBundle::load_selections(AppConfig &config, const PresetPreferences& p
this->filament_presets.emplace_back(remove_ini_suffix(f_name));
}
update_filament_count();
// Load data from AppConfig to ProjectConfig when Studio is initialized.
std::vector<std::string> filament_colors;
auto f_colors = config.get_printer_setting(initial_printer_profile_name, "filament_colors");
@@ -3779,6 +3784,18 @@ int PresetBundle::get_printer_extruder_count() const
return count;
}
void PresetBundle::update_filament_count()
{
if (printers.get_edited_preset().printer_technology() != ptFFF)
return;
const size_t num_extruders = static_cast<size_t>(get_printer_extruder_count());
if (filament_presets.size() >= num_extruders)
return;
filament_presets.resize(num_extruders, filament_presets.empty()
? filaments.first_visible().name
: filament_presets.back());
}
bool PresetBundle::support_different_extruders()
{
Preset& printer_preset = this->printers.get_edited_preset();

View File

@@ -372,6 +372,12 @@ public:
int get_printer_extruder_count() const;
bool support_different_extruders();
// Orca: Ensure filament_presets has at least one slot per nozzle on FFF printers.
// Called from (load|update)_selections before the parallel project_config arrays
// (filament_colour/colour_type/map) are sized off filament_presets.size(), so a
// short saved filament list doesn't truncate the loaded colors.
void update_filament_count();
// Load user configuration and store it into the user profiles.
// This method is called by the configuration wizard.
void load_config_from_wizard(const std::string &name, DynamicPrintConfig config, Semver file_version)