fix memory leak in SketchObject::transferConstraints
This commit is contained in:
parent
9c1134940b
commit
bf129d3a33
|
@ -887,6 +887,7 @@ int SketchObject::transferConstraints(int fromGeoId, PointPos fromPosId, int toG
|
||||||
{
|
{
|
||||||
const std::vector<Constraint *> &vals = this->Constraints.getValues();
|
const std::vector<Constraint *> &vals = this->Constraints.getValues();
|
||||||
std::vector<Constraint *> newVals(vals);
|
std::vector<Constraint *> newVals(vals);
|
||||||
|
std::vector<Constraint *> changed;
|
||||||
for (int i=0; i < int(newVals.size()); i++) {
|
for (int i=0; i < int(newVals.size()); i++) {
|
||||||
if (vals[i]->First == fromGeoId && vals[i]->FirstPos == fromPosId &&
|
if (vals[i]->First == fromGeoId && vals[i]->FirstPos == fromPosId &&
|
||||||
!(vals[i]->Second == toGeoId && vals[i]->SecondPos == toPosId)) {
|
!(vals[i]->Second == toGeoId && vals[i]->SecondPos == toPosId)) {
|
||||||
|
@ -894,15 +895,25 @@ int SketchObject::transferConstraints(int fromGeoId, PointPos fromPosId, int toG
|
||||||
constNew->First = toGeoId;
|
constNew->First = toGeoId;
|
||||||
constNew->FirstPos = toPosId;
|
constNew->FirstPos = toPosId;
|
||||||
newVals[i] = constNew;
|
newVals[i] = constNew;
|
||||||
} else if (vals[i]->Second == fromGeoId && vals[i]->SecondPos == fromPosId &&
|
changed.push_back(constNew);
|
||||||
|
}
|
||||||
|
else if (vals[i]->Second == fromGeoId && vals[i]->SecondPos == fromPosId &&
|
||||||
!(vals[i]->First == toGeoId && vals[i]->FirstPos == toPosId)) {
|
!(vals[i]->First == toGeoId && vals[i]->FirstPos == toPosId)) {
|
||||||
Constraint *constNew = newVals[i]->clone();
|
Constraint *constNew = newVals[i]->clone();
|
||||||
constNew->Second = toGeoId;
|
constNew->Second = toGeoId;
|
||||||
constNew->SecondPos = toPosId;
|
constNew->SecondPos = toPosId;
|
||||||
newVals[i] = constNew;
|
newVals[i] = constNew;
|
||||||
|
changed.push_back(constNew);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// assign the new values only if something has changed
|
||||||
|
if (!changed.empty()) {
|
||||||
this->Constraints.setValues(newVals);
|
this->Constraints.setValues(newVals);
|
||||||
|
// free memory
|
||||||
|
for (Constraint* it : changed)
|
||||||
|
delete it;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user