From 00822b0a805e640b09d6b1fb5f52b7ecefbb77a4 Mon Sep 17 00:00:00 2001 From: marioalexis Date: Sat, 9 Jan 2021 11:52:51 -0300 Subject: [PATCH] Gui: Prevent crash when trying to access sub-objects of a deleted object from a SelectionObject --- src/Gui/SelectionObjectPyImp.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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;