diff --git a/src/Gui/SelectionObjectPyImp.cpp b/src/Gui/SelectionObjectPyImp.cpp index 14a320cd60..7f685dee2c 100644 --- a/src/Gui/SelectionObjectPyImp.cpp +++ b/src/Gui/SelectionObjectPyImp.cpp @@ -116,18 +116,23 @@ Py::Object SelectionObjectPy::getObject(void) const Py::Tuple SelectionObjectPy::getSubObjects(void) const { - std::vector objs; + App::DocumentObject *obj = getSelectionObjectPtr()->getObject(); + if (!obj) + throw Py::RuntimeError("Cannot get sub-objects of deleted object"); + + std::vector subObjs; for(const auto &subname : getSelectionObjectPtr()->getSubNames()) { PyObject *pyObj=0; Base::Matrix4D mat; - getSelectionObjectPtr()->getObject()->getSubObject(subname.c_str(),&pyObj,&mat); - if(pyObj) objs.push_back(pyObj); + obj->getSubObject(subname.c_str(),&pyObj,&mat); + if(pyObj) + subObjs.push_back(pyObj); } - Py::Tuple temp(objs.size()); + Py::Tuple temp(subObjs.size()); Py::sequence_index_type index = 0; - for(std::vector::const_iterator it= objs.begin();it!=objs.end();++it) + for(std::vector::const_iterator it= subObjs.begin();it!=subObjs.end();++it) temp.setItem(index++, Py::asObject(*it)); return temp;