From 387b8fcd9e5c576cd5e9b5fb0eb7d2ca3e674efc Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 13 Nov 2013 12:29:06 +0100 Subject: [PATCH] + Throw exception when querying information from invalid shape --- src/Mod/Part/App/TopoShapePyImp.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Mod/Part/App/TopoShapePyImp.cpp b/src/Mod/Part/App/TopoShapePyImp.cpp index 7d1c3f5a7..d61189d2c 100644 --- a/src/Mod/Part/App/TopoShapePyImp.cpp +++ b/src/Mod/Part/App/TopoShapePyImp.cpp @@ -1716,22 +1716,31 @@ Py::List TopoShapePy::getCompounds(void) const Py::Float TopoShapePy::getLength(void) const { + const TopoDS_Shape& shape = getTopoShapePtr()->_Shape; + if (shape.IsNull()) + throw Py::RuntimeError("shape is invalid"); GProp_GProps props; - BRepGProp::LinearProperties(getTopoShapePtr()->_Shape, props); + BRepGProp::LinearProperties(shape, props); return Py::Float(props.Mass()); } Py::Float TopoShapePy::getArea(void) const { + const TopoDS_Shape& shape = getTopoShapePtr()->_Shape; + if (shape.IsNull()) + throw Py::RuntimeError("shape is invalid"); GProp_GProps props; - BRepGProp::SurfaceProperties(getTopoShapePtr()->_Shape, props); + BRepGProp::SurfaceProperties(shape, props); return Py::Float(props.Mass()); } Py::Float TopoShapePy::getVolume(void) const { + const TopoDS_Shape& shape = getTopoShapePtr()->_Shape; + if (shape.IsNull()) + throw Py::RuntimeError("shape is invalid"); GProp_GProps props; - BRepGProp::VolumeProperties(getTopoShapePtr()->_Shape, props); + BRepGProp::VolumeProperties(shape, props); return Py::Float(props.Mass()); }