+ fixes #0001720: Freecad crash when handling invalid sketches

This commit is contained in:
wmayer
2014-12-28 17:10:54 +01:00
parent 6a211b9dbe
commit 7d8b1f30c3
3 changed files with 55 additions and 31 deletions

View File

@@ -236,6 +236,10 @@ PyObject* SketchObjectPy::addConstraint(PyObject *args)
if (PyObject_TypeCheck(pcObj, &(Sketcher::ConstraintPy::Type))) {
Sketcher::Constraint *constr = static_cast<Sketcher::ConstraintPy*>(pcObj)->getConstraintPtr();
if (!this->getSketchObjectPtr()->evaluateConstraint(constr)) {
PyErr_SetString(PyExc_IndexError, "Constraint has invalid indexes");
return 0;
}
int ret = this->getSketchObjectPtr()->addConstraint(constr);
this->getSketchObjectPtr()->solve();
return Py::new_reference_to(Py::Int(ret));
@@ -251,6 +255,12 @@ PyObject* SketchObjectPy::addConstraint(PyObject *args)
}
}
for (std::vector<Constraint*>::iterator it = values.begin(); it != values.end(); ++it) {
if (!this->getSketchObjectPtr()->evaluateConstraint(*it)) {
PyErr_SetString(PyExc_IndexError, "Constraint has invalid indexes");
return 0;
}
}
int ret = getSketchObjectPtr()->addConstraints(values) + 1;
std::size_t numCon = values.size();
Py::Tuple tuple(numCon);