Gui: Prevent crash when trying to access a deleted object from a SelectionObject

This commit is contained in:
marioalexis
2021-01-01 05:26:30 -03:00
committed by abdullahtahiriyo
parent d667dd7102
commit daca7843ee
2 changed files with 9 additions and 3 deletions

View File

@@ -100,12 +100,18 @@ Py::String SelectionObjectPy::getDocumentName(void) const
Py::Object SelectionObjectPy::getDocument(void) const
{
return Py::Object(getSelectionObjectPtr()->getObject()->getDocument()->getPyObject(), true);
App::DocumentObject *obj = getSelectionObjectPtr()->getObject();
if (!obj)
throw Py::RuntimeError("Cannot get document of deleted object");
return Py::Object(obj->getDocument()->getPyObject(), true);
}
Py::Object SelectionObjectPy::getObject(void) const
{
return Py::Object(getSelectionObjectPtr()->getObject()->getPyObject(), true);
App::DocumentObject *obj = getSelectionObjectPtr()->getObject();
if (!obj)
throw Py::RuntimeError("Object already deleted");
return Py::Object(obj->getPyObject(), true);
}
Py::Tuple SelectionObjectPy::getSubObjects(void) const