Issue
So I am getting a stack trace when my python qt app shutsdown. It is crashing when *iter is dereferenced. Here is the snippet from pyside basewrapper.cpp
static void decRefPyObjectList(const std::list<PyObject*>& lst, PyObject *skip)
{
std::list<PyObject*>::const_iterator iter = lst.begin();
while(iter != lst.end()) {
if (*iter != skip) // causes segfault
Py_DECREF(*iter);
++iter;
}
}
From backtrace:
#0 0x00007f6ea2c22653 in Shiboken::decRefPyObjectList (lst=, skip=0x0) at debug/shiboken-1.2.2/libshiboken/basewrapper.cpp:595
#1 0x00007f6ea2c24e44 in Shiboken::Object::clearReferences (self=0x7f6e7260c908) at debug/shiboken-1.2.2/libshiboken/basewrapper.cpp:1361
#2 0x00007f6ea2c23f86 in Shiboken::Object::destroy (self=0x7f6e7260c908, cppData=0x7f6e540f1220) at debug/shiboken-1.2.2/libshiboken/basewrapper.cpp:1127
#3 0x00007f6ea0f29d4f in QDataWidgetMapperWrapper::~QDataWidgetMapperWrapper (this=0x7f6e540f1220, __in_chrg=<optimized out>) at debug/pyside-qt4.8+1.2.2/build/PySide/QtGui/PySide/QtGui/qdatawidgetmapper_wrapper.cpp:309
Any tips on what situation might cause this? From reviewing the stack trace it is happening during QT/PySide tear down. When it goes to clean up all the object references.
Solution
It turns out that Python garbage collector was grabbing the reference and then PySide was trying to clean up the same reference.
The solution was to explicitly hold a reference to said object in python. In our case it was a model we attached to QT.
Within a class that subclasses QDataWidgetMapper. This breaks, model is the offender, it is not stored outside the mapper meaning it is a loose reference for the GC to pick up:
def setModel(self, model):
QDataWidgetMapper.setModel(self, model)
Change to:
def setModel(self, model):
self._model = model
QDataWidgetMapper.setModel(self, model)
Now we are storing explicitly a reference to model, it won't get garbage collected and PySide can clean it up.
Answered By - Halsafar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.