Fix for #10941 - Prusa 2.6.0 freezes when trying to change color

This commit is contained in:
YuSanka 2023-08-07 15:30:44 +02:00
parent e9d967f4b2
commit 096d10ef62

View File

@ -2757,6 +2757,11 @@ bool TickCodeInfo::add_tick(const int tick, Type type, const int extruder, doubl
bool TickCodeInfo::edit_tick(std::set<TickCode>::iterator it, double print_z) bool TickCodeInfo::edit_tick(std::set<TickCode>::iterator it, double print_z)
{ {
// Save previously value of the tick before the call a Dialog from get_... functions,
// otherwise a background process can change ticks values and current iterator wouldn't be valid for the moment of a Dialog close
// and PS will crash (see https://github.com/prusa3d/PrusaSlicer/issues/10941)
TickCode changed_tick = *it;
std::string edited_value; std::string edited_value;
if (it->type == ColorChange) if (it->type == ColorChange)
edited_value = get_new_color(it->color); edited_value = get_new_color(it->color);
@ -2768,7 +2773,10 @@ bool TickCodeInfo::edit_tick(std::set<TickCode>::iterator it, double print_z)
if (edited_value.empty()) if (edited_value.empty())
return false; return false;
TickCode changed_tick = *it; // Update iterator. For this moment its value can be invalid
if (it = ticks.find(changed_tick); it == ticks.end())
return false;
if (it->type == ColorChange) { if (it->type == ColorChange) {
if (it->color == edited_value) if (it->color == edited_value)
return false; return false;