PySide Segfault on shutdown

So I am getting a stack trace when my python qt app is shutting down. It crashes when * iter is dereferenced. Here is a 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 clues as to what situation might be causing this? From the overview, the stack trace occurs during a break in QT / PySide. When it goes to clear all object references.

+3


source to share


1 answer


It turns out that the Python garbage collector was hijacking the link and then PySide was trying to clean up the same link.

The solution was to explicitly refer to the specified object in python. In our case, this was the model that we tied to QT.

In a class that subclasses QDataWidgetMapper. This breaks down, the model is offending, it is not stored outside the mapper, that is, it is a free 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 explicitly save the reference to the model, it will not be garbage collected and PySide can clean it up.

+2


source







All Articles