Salome HOME
#878 Segmentation fault when setting distance on the two same points
[modules/shaper.git] / src / SketchSolver / SketchSolver_Solver.cpp
index 650e11c2d79b12c9a261e355c45500c1358acd5d..4e7a4f0e9269f7e2d76ad8219a130fce099864f3 100644 (file)
@@ -31,6 +31,8 @@ SketchSolver_Solver::SketchSolver_Solver()
 
 SketchSolver_Solver::~SketchSolver_Solver()
 {
+  if (myEquationsSystem.constraint)
+    delete[] myEquationsSystem.constraint;
   if (myEquationsSystem.failed)
     delete[] myEquationsSystem.failed;
 }
@@ -56,8 +58,18 @@ void SketchSolver_Solver::setEntities(Slvs_Entity* theEntities, int theSize)
 
 void SketchSolver_Solver::setConstraints(Slvs_Constraint* theConstraints, int theSize)
 {
-  myEquationsSystem.constraint = theConstraints;
-  myEquationsSystem.constraints = theSize;
+  if (!myEquationsSystem.constraint) {
+    myEquationsSystem.constraint = new Slvs_Constraint[theSize];
+    myEquationsSystem.constraints = theSize;
+  }
+  else if (myEquationsSystem.constraints != theSize) {
+    if (theSize > myEquationsSystem.constraints) {
+      delete[] myEquationsSystem.constraint;
+      myEquationsSystem.constraint = new Slvs_Constraint[theSize];
+    }
+    myEquationsSystem.constraints = theSize;
+  }
+  memcpy(myEquationsSystem.constraint, theConstraints, theSize * sizeof(Slvs_Constraint));
 }