Skip to content

Commit

Permalink
Merge branch 'ys_crash_spe2136' into master_27x
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasmatena committed Mar 22, 2024
2 parents cdcd4da + 207d1ab commit 4b5ee2d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/libslic3r/Preset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2235,6 +2235,14 @@ const std::string& ExtruderFilaments::get_preset_name_by_alias(const std::string
return alias;
}

void ExtruderFilaments::select_filament(size_t idx)
{
assert(idx == size_t(-1) || idx < m_extr_filaments.size());
// Check idx befor saving it's value to m_idx_selected.
// Invalidate m_idx_selected, if idx is out of range m_extr_filaments
m_idx_selected = (idx == size_t(-1) || idx < m_extr_filaments.size()) ? idx : size_t(-1);
}

bool ExtruderFilaments::select_filament(const std::string &name_w_suffix, bool force/*= false*/)
{
std::string name = Preset::remove_suffix_modified(name_w_suffix);
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/Preset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ class ExtruderFilaments
// Select filament by the full filament name, which contains name of filament, separator and name of selected preset
// If full_name doesn't contain name of selected preset, then select first preset in the list for this filament
bool select_filament(const std::string& name, bool force = false);
void select_filament(size_t idx) { m_idx_selected = idx; }
void select_filament(size_t idx);

std::string get_selected_preset_name() const { return m_idx_selected == size_t(-1) ? std::string() : m_extr_filaments[m_idx_selected].preset->name; }
const Preset* get_selected_preset() const { return m_idx_selected == size_t(-1) ? nullptr : m_extr_filaments[m_idx_selected].preset; }
Expand Down
4 changes: 4 additions & 0 deletions src/libslic3r/PresetBundle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,8 @@ ConfigSubstitutions PresetBundle::load_config_file_config_bundle(
load_one(this->printers, tmp_bundle.printers, tmp_bundle.printers .get_selected_preset_name(), true);

this->extruders_filaments.clear();
this->extruders_filaments.emplace_back(ExtruderFilaments(&filaments));

this->update_multi_material_filament_presets();
for (size_t i = 1; i < std::min(tmp_bundle.extruders_filaments.size(), this->extruders_filaments.size()); ++i)
this->extruders_filaments[i].select_filament(load_one(this->filaments, tmp_bundle.filaments, tmp_bundle.extruders_filaments[i].get_selected_preset_name(), false));
Expand Down Expand Up @@ -1700,6 +1702,8 @@ std::pair<PresetsConfigSubstitutions, size_t> PresetBundle::load_configbundle(

// Extruder_filaments have to be recreated with new loaded filaments
this->extruders_filaments.clear();
this->extruders_filaments.emplace_back(ExtruderFilaments(&filaments));

this->update_multi_material_filament_presets();
for (size_t i = 0; i < std::min(this->extruders_filaments.size(), active_filaments.size()); ++ i)
this->extruders_filaments[i].select_filament(filaments.find_preset(active_filaments[i], true)->name);
Expand Down

0 comments on commit 4b5ee2d

Please sign in to comment.