mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-12 20:19:09 +08:00
ExtruderFilaments: Check index of a selected filament to avoid an out of range.
This commit is contained in:
parent
17f628fe52
commit
207d1ab026
@ -2235,6 +2235,14 @@ const std::string& ExtruderFilaments::get_preset_name_by_alias(const std::string
|
|||||||
return alias;
|
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*/)
|
bool ExtruderFilaments::select_filament(const std::string &name_w_suffix, bool force/*= false*/)
|
||||||
{
|
{
|
||||||
std::string name = Preset::remove_suffix_modified(name_w_suffix);
|
std::string name = Preset::remove_suffix_modified(name_w_suffix);
|
||||||
|
@ -906,7 +906,7 @@ public:
|
|||||||
// Select filament by the full filament name, which contains name of filament, separator and name of selected preset
|
// 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
|
// 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);
|
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; }
|
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; }
|
const Preset* get_selected_preset() const { return m_idx_selected == size_t(-1) ? nullptr : m_extr_filaments[m_idx_selected].preset; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user