Gui: Use Py::SmartPtr instead of raw pointer
Using the raw pointer may result into a crash in case the Python object is accessed by the interpreter after the NavigationStyle has been destroyed.
This commit is contained in:
@@ -319,10 +319,10 @@ NavigationStyle::~NavigationStyle()
|
||||
finalize();
|
||||
delete this->animator;
|
||||
|
||||
if (pythonObject) {
|
||||
if (!pythonObject.is(nullptr)) {
|
||||
Base::PyGILStateLocker lock;
|
||||
Py_DECREF(pythonObject);
|
||||
pythonObject = nullptr;
|
||||
Base::PyObjectBase* obj = static_cast<Base::PyObjectBase*>(pythonObject.ptr());
|
||||
obj->setInvalid();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1914,11 +1914,11 @@ void NavigationStyle::openPopupMenu(const SbVec2s& position)
|
||||
|
||||
PyObject* NavigationStyle::getPyObject()
|
||||
{
|
||||
if (!pythonObject)
|
||||
pythonObject = new NavigationStylePy(this);
|
||||
|
||||
Py_INCREF(pythonObject);
|
||||
return pythonObject;
|
||||
if (pythonObject.is(nullptr)) {
|
||||
// ref counter is set to 1
|
||||
pythonObject = Py::asObject(new NavigationStylePy(this));
|
||||
}
|
||||
return Py::new_reference_to(pythonObject);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
|
||||
#include <QEvent>
|
||||
#include <Base/BaseClass.h>
|
||||
#include <Base/SmartPtrPy.h>
|
||||
#include <Gui/Namespace.h>
|
||||
#include <FCGlobal.h>
|
||||
#include <memory>
|
||||
@@ -283,7 +284,7 @@ protected:
|
||||
SbSphereSheetProjector * spinprojector;
|
||||
//@}
|
||||
|
||||
PyObject* pythonObject;
|
||||
Py::SmartPtr pythonObject;
|
||||
|
||||
private:
|
||||
friend class NavigationAnimator;
|
||||
|
||||
Reference in New Issue
Block a user