Skip to content

Commit

Permalink
Gui: Prevent crash when trying to access a deleted object from a Sele…
Browse files Browse the repository at this point in the history
…ctionObject
  • Loading branch information
marioalexis84 authored and abdullahtahiriyo committed Jan 7, 2021
1 parent 94405e3 commit 1bfd764
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Gui/SelectionObjectPy.xml
Expand Up @@ -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>
Expand Down
10 changes: 8 additions & 2 deletions src/Gui/SelectionObjectPyImp.cpp
Expand Up @@ -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
Expand Down

0 comments on commit 1bfd764

Please sign in to comment.