Sketcher: Fix crash on constraint rename

========================================

Report:
https://github.com/FreeCAD/FreeCAD/pull/4183
https://github.com/realthunder/FreeCAD_assembly3/issues/387

Problem:
renameConstraint() previously implemented exclusively in SketchObjectPyImp.cpp,
will change the Constraints property without updating the solver. A prospective
drag operation would rely on a deleted pointer constraint which leads to the
crash.

Solution:
- mark the solver status as needing an update
- leverage new through sketchobject r/w interface to ensure solver is synchronised
before the temporary move operation starts

Bonus:
move the core of the function to SketchObject.cpp so that input data validity
check on constraint change is inhibited.
This commit is contained in:
Abdullah Tahiri
2020-12-24 11:54:18 +01:00
committed by abdullahtahiriyo
parent 1d56289c79
commit 64774bc1fe
3 changed files with 47 additions and 13 deletions

View File

@@ -417,14 +417,8 @@ PyObject* SketchObjectPy::renameConstraint(PyObject *args)
}
}
// only change the constraint item if the names are different
const Constraint* item = this->getSketchObjectPtr()->Constraints[Index];
if (item->Name != Name) {
Constraint* copy = item->clone();
copy->Name = Name;
this->getSketchObjectPtr()->Constraints.set1Value(Index, copy);
delete copy;
}
this->getSketchObjectPtr()->renameConstraint(Index, Name);
Py_Return;
}