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 94405e33c7
commit 1bfd7644b2
2 changed files with 9 additions and 3 deletions

View File

@@ -56,7 +56,7 @@
</Attribute>
<Attribute Name="Document" ReadOnly="true">
<Documentation>
<UserDocu>Selected document</UserDocu>
<UserDocu>Document of the selected object</UserDocu>
</Documentation>
<Parameter Name="Document" Type="Object" />
</Attribute>

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