Salome HOME
[bos#40730] Random crash when running script in terminal mbs/bos40730_random_crash 38/head
authormbs <martin.bernhard@opencascade.com>
Thu, 25 Jan 2024 16:38:44 +0000 (16:38 +0000)
committermbs <martin.bernhard@opencascade.com>
Thu, 25 Jan 2024 16:38:44 +0000 (16:38 +0000)
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp

index 8e738d23da1dfde96ca9983fa84185610efad5cb..aecba9754987f43a7145b98660d1222c502e5ae1 100644 (file)
@@ -477,10 +477,18 @@ void PlaneGCSSolver_Storage::adjustParametrizationOfArcs()
 
   // update parameters of Middle point constraint for point on arc
   std::map<ConstraintPtr, ConstraintWrapperPtr>::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<ConstraintPtr, ConstraintWrapperPtr>::iterator aNextCIt = aCIt;
+  for (; aCIt != myConstraintMap.end(); aCIt=aNextCIt) {
+    ++aNextCIt;
     if (aCIt->second->type() == CONSTRAINT_MIDDLE_POINT) {
       notify(aCIt->first);
     }
+  }
 }