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:
committed by
abdullahtahiriyo
parent
04bbae80cf
commit
56f3db079f
@@ -8002,6 +8002,27 @@ int SketchObject::autoRemoveRedundants(bool updategeo)
|
||||
return redundants.size();
|
||||
}
|
||||
|
||||
int SketchObject::renameConstraint(int GeoId, std::string name)
|
||||
{
|
||||
// only change the constraint item if the names are different
|
||||
const Constraint* item = Constraints[GeoId];
|
||||
|
||||
if (item->Name != name) {
|
||||
Base::StateLocker lock(managedoperation, true); // no need to check input data validity as this is an sketchobject managed operation.
|
||||
|
||||
Constraint* copy = item->clone();
|
||||
copy->Name = name;
|
||||
|
||||
Constraints.set1Value(GeoId, copy);
|
||||
delete copy;
|
||||
|
||||
solverNeedsUpdate = true; // make sure any prospective solver access updates the constraint pointer that just got invalidated
|
||||
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::vector<Base::Vector3d> SketchObject::getOpenVertices(void) const
|
||||
{
|
||||
std::vector<Base::Vector3d> points;
|
||||
|
||||
Reference in New Issue
Block a user