FIX: crash when delete filament with setting support filament

jira: STUDIO-11063
Change-Id: I72ede85e540178b576239615d67017c082ded113
This commit is contained in:
zhimin.zeng 2025-03-22 18:04:27 +08:00 committed by lane.wei
parent be16678e70
commit bef139898a
2 changed files with 27 additions and 13 deletions

View File

@ -724,19 +724,35 @@ void ObjectList::update_filament_values_for_items_when_delete_filament(const siz
m_objects_model->SetExtruder(extruder, item);
static const char *keys[] = {"support_filament", "support_interface_filament"};
for (auto key : keys)
if (object->config.has(key) && object->config.opt_int(key) == filament_id + 1) {
if (replace_id == -1)
for (auto key : keys) {
if (object->config.has(key)) {
if(object->config.opt_int(key) == filament_id + 1)
object->config.erase(key);
else
object->config.set_key_value(key, new ConfigOptionInt(replace_filament_id));
else {
int new_value = object->config.opt_int(key) > filament_id ? object->config.opt_int(key) - 1 : object->config.opt_int(key);
object->config.set_key_value(key, new ConfigOptionInt(new_value));
}
}
}
//if (object->volumes.size() > 1) {
for (size_t id = 0; id < object->volumes.size(); id++) {
item = m_objects_model->GetItemByVolumeId(i, id);
if (!item)
continue;
for (auto key : keys) {
if (object->volumes[id]->config.has(key)) {
if (object->volumes[id]->config.opt_int(key) == filament_id + 1)
object->volumes[id]->config.erase(key);
else {
int new_value = object->volumes[id]->config.opt_int(key) > filament_id ? object->volumes[id]->config.opt_int(key) - 1 :
object->volumes[id]->config.opt_int(key);
object->config.set_key_value(key, new ConfigOptionInt(new_value));
}
}
}
if (!object->volumes[id]->config.has("extruder")) {
continue;
}
@ -749,10 +765,6 @@ void ObjectList::update_filament_values_for_items_when_delete_filament(const siz
}
m_objects_model->SetExtruder(extruder, item);
for (auto key : keys)
if (object->volumes[id]->config.has(key) && object->volumes[id]->config.opt_int(key) == filament_id + 1)
object->volumes[id]->config.erase(key);
}
//}

View File

@ -14948,11 +14948,13 @@ void Plater::on_filaments_delete(size_t num_filaments, size_t filament_id, int r
// update global support filament
static const char *keys[] = {"support_filament", "support_interface_filament"};
for (auto key : keys)
if (p->config->has(key) && p->config->opt_int(key) == filament_id + 1) {
if (replace_filament_id == -1)
if (p->config->has(key)) {
if(p->config->opt_int(key) == filament_id + 1)
(*(p->config)).erase(key);
else
(*(p->config)).set_key_value(key, new ConfigOptionInt(replace_filament_id + 1));
else {
int new_value = p->config->opt_int(key) > filament_id ? p->config->opt_int(key) - 1 : p->config->opt_int(key);
(*(p->config)).set_key_value(key, new ConfigOptionInt(new_value));
}
}
// update object/volume/support(object and volume) filament id