From 4fcd770080ec6ba33d3985ee2b9f13c4cf34caef Mon Sep 17 00:00:00 2001 From: mbs Date: Thu, 25 Jan 2024 16:38:44 +0000 Subject: [PATCH] [bos#40730] Random crash when running script in terminal --- .../PlaneGCSSolver/PlaneGCSSolver_Storage.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp index 8e738d23d..aecba9754 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp @@ -477,10 +477,18 @@ void PlaneGCSSolver_Storage::adjustParametrizationOfArcs() // update parameters of Middle point constraint for point on arc std::map::iterator aCIt = myConstraintMap.begin(); - for (; aCIt != myConstraintMap.end(); ++aCIt) + // [bos#40730] Random crash when running script from terminal: + // In this specific case, when iterating over all constraints and finding a MiddlePoint + // constraint, it gets notified, causing it to be removed and readded to the map. + // At that time, the iterator gets out-of-date and iterating further leads to invalid + // pointers, causing the crash. + std::map::iterator aNextCIt = aCIt; + for (; aCIt != myConstraintMap.end(); aCIt=aNextCIt) { + ++aNextCIt; if (aCIt->second->type() == CONSTRAINT_MIDDLE_POINT) { notify(aCIt->first); } + } } -- 2.39.2