From 096d10ef62b5cd47695d2f2004274a4a5a448ae3 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Mon, 7 Aug 2023 15:30:44 +0200 Subject: [PATCH] Fix for #10941 - Prusa 2.6.0 freezes when trying to change color --- src/slic3r/GUI/DoubleSlider.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/DoubleSlider.cpp b/src/slic3r/GUI/DoubleSlider.cpp index 380e2f5b7e..d96e794621 100644 --- a/src/slic3r/GUI/DoubleSlider.cpp +++ b/src/slic3r/GUI/DoubleSlider.cpp @@ -2757,6 +2757,11 @@ bool TickCodeInfo::add_tick(const int tick, Type type, const int extruder, doubl bool TickCodeInfo::edit_tick(std::set::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; if (it->type == ColorChange) edited_value = get_new_color(it->color); @@ -2768,7 +2773,10 @@ bool TickCodeInfo::edit_tick(std::set::iterator it, double print_z) if (edited_value.empty()) 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->color == edited_value) return false;