Fix crash at exit when there's a chain of referenced objects.
Reviewer: Luciano Wolf <luciano.wolf@openbossa.org>
Marcelo Lira <marcelo.lira@openbossa.org>
This commit is contained in:
parent
f31d910755
commit
47aa718978
1 changed files with 15 additions and 13 deletions
|
|
@ -32,6 +32,7 @@
|
||||||
#include <basewrapper.h>
|
#include <basewrapper.h>
|
||||||
#include <conversions.h>
|
#include <conversions.h>
|
||||||
#include <typeresolver.h>
|
#include <typeresolver.h>
|
||||||
|
#include <bindingmanager.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <QStack>
|
#include <QStack>
|
||||||
|
|
@ -102,6 +103,18 @@ void runCleanupFunctions()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void destructionVisitor(SbkObject* pyObj, void* data)
|
||||||
|
{
|
||||||
|
void** realData = reinterpret_cast<void**>(data);
|
||||||
|
SbkObject* pyQApp = reinterpret_cast<SbkObject*>(realData[0]);
|
||||||
|
PyTypeObject* pyQObjectType = reinterpret_cast<PyTypeObject*>(realData[1]);
|
||||||
|
|
||||||
|
if (pyObj != pyQApp && PyObject_TypeCheck(pyObj, pyQObjectType)) {
|
||||||
|
if (Shiboken::Object::hasOwnership(pyObj))
|
||||||
|
Shiboken::callCppDestructor<QObject>(Shiboken::Object::cppPointer(pyObj, Shiboken::SbkType<QObject*>()));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
void destroyQCoreApplication()
|
void destroyQCoreApplication()
|
||||||
{
|
{
|
||||||
SignalManager::instance().clear();
|
SignalManager::instance().clear();
|
||||||
|
|
@ -114,19 +127,8 @@ void destroyQCoreApplication()
|
||||||
PyTypeObject* pyQObjectType = Shiboken::TypeResolver::get("QObject*")->pythonType();
|
PyTypeObject* pyQObjectType = Shiboken::TypeResolver::get("QObject*")->pythonType();
|
||||||
assert(pyQObjectType);
|
assert(pyQObjectType);
|
||||||
|
|
||||||
QList<SbkObject*> objects;
|
void* data[2] = {pyQApp, pyQObjectType};
|
||||||
|
bm.visitAllPyObjects(&destructionVisitor, &data);
|
||||||
//filter only QObjects which we have ownership, this will avoid list changes during the destruction of some parent object
|
|
||||||
foreach (SbkObject* pyObj, bm.getAllPyObjects()) {
|
|
||||||
if (pyObj != pyQApp && PyObject_TypeCheck(pyObj, pyQObjectType)) {
|
|
||||||
if (Shiboken::Object::hasOwnership(pyObj))
|
|
||||||
objects << pyObj;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Now we can destroy all object in the list
|
|
||||||
foreach (SbkObject* pyObj, objects)
|
|
||||||
Shiboken::callCppDestructor<QObject>(Shiboken::Object::cppPointer(pyObj, Shiboken::SbkType<QObject*>()));
|
|
||||||
|
|
||||||
// in the end destroy app
|
// in the end destroy app
|
||||||
delete app;
|
delete app;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue