From: mbs Date: Thu, 25 Jan 2024 16:38:44 +0000 (+0000) Subject: [bos#40730] Random crash when running script in terminal X-Git-Tag: V9_13_0a1~24 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4fcd770080ec6ba33d3985ee2b9f13c4cf34caef;p=modules%2Fshaper.git [bos#40730] Random crash when running script in terminal --- 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); } + } }