PDA

View Full Version : Acces violation during QGraphicsScene destruction ?



pl01
3rd January 2011, 13:15
Hi,

When I close my application I got a crash (access violation) in the desctructor of QGraphicsScene. I don't understand what mean this code :-P but maybe someone of you have 'expert' knowledge and can help me ?

Just for information, The QGraphicsScene has no parent.

The error :
Unhandled exception at 0x6506319a (QtGuid4.dll) in pureStudio.exe: 0xC0000005: Access violation reading location 0x00000004.

The stack

QtGuid4.dll!QScopedPointer<QObjectData,QScopedPointerDeleter<QObjectData> >::data() Line 135 + 0x3 bytes C++
QtGuid4.dll!qGetPtrHelper<QScopedPointer<QObjectData,QScopedPointerDeleter<QObjectData> > >(const QScopedPointer<QObjectData,QScopedPointerDeleter<QObjectData> > & p={...}) Line 2338 + 0xb bytes C++
QtGuid4.dll!QApplication::d_func() Line 379 + 0x13 bytes C++
QtGuid4.dll!QGraphicsScene::~QGraphicsScene() Line 1630 + 0x17 bytes C++
pureStudio.exe!pureStudio::pgEditor::QNodesScene:: ~QNodesScene() Line 43 + 0x2e bytes C++
pureStudio.exe!pureStudio::pgEditor::QNodesScene:: `scalar deleting destructor'() + 0xf bytes C++
QtCored4.dll!QObjectPrivate::deleteChildren() Line 1949 + 0x24 bytes C++
QtCored4.dll!QObject::~QObject() Line 947 C++
QtCored4.dll!QCoreApplication::~QCoreApplication() Line 648 + 0xf bytes C++
QtGuid4.dll!QApplication::~QApplication() Line 1195 + 0x13 bytes C++
pureStudio.exe!main(int argc=1, char * * argv=0x009a90c0) Line 26 + 0x2e bytes C++
pureStudio.exe!WinMain(HINSTANCE__ * instance=0x00fd0000, HINSTANCE__ * prevInstance=0x00000000, char * __formal=0x00417809, int cmdShow=1) Line 131 + 0x12 bytes C++
pureStudio.exe!__tmainCRTStartup() Line 574 + 0x35 bytes C
pureStudio.exe!WinMainCRTStartup() Line 399 C

qscopedpointer.h :



inline T *data() const
{
return d;
}


QGraphicsScene.h



QGraphicsScene::~QGraphicsScene()
{
Q_D(QGraphicsScene);

// Remove this scene from qApp's global scene list.
qApp->d_func()->scene_list.removeAll(this);

clear();

// Remove this scene from all associated views.
for (int j = 0; j < d->views.size(); ++j)
d->views.at(j)->setScene(0);
}

high_flyer
3rd January 2011, 13:39
The problem only comes to surface at QGraphicsScene, but it is in your code.
Can you show your ~QNodesScene() destructor?

pl01
3rd January 2011, 13:59
There is nothing here !

QNodesScene::~QNodesScene()
{
}

high_flyer
3rd January 2011, 14:02
Ok, so the code that calls it...

pl01
3rd January 2011, 14:06
It is the QT Lib code ! Here it is :



QCoreApplication::~QCoreApplication()
{
qt_call_post_routines();

self = 0;
QCoreApplicationPrivate::is_app_closing = true;
QCoreApplicationPrivate::is_app_running = false;

#if !defined(QT_NO_THREAD)
#if !defined(QT_NO_CONCURRENT)
// Synchronize and stop the global thread pool threads.
QThreadPool *globalThreadPool = 0;
QT_TRY {
globalThreadPool = QThreadPool::globalInstance();
} QT_CATCH (...) {
// swallow the exception, since destructors shouldn't throw
}
if (globalThreadPool)
globalThreadPool->waitForDone();
#endif
QThread::cleanup();
#endif

d_func()->threadData->eventDispatcher = 0;
if (QCoreApplicationPrivate::eventDispatcher)
QCoreApplicationPrivate::eventDispatcher->closingDown();
QCoreApplicationPrivate::eventDispatcher = 0;

#ifndef QT_NO_LIBRARY
delete coreappdata()->app_libpaths;
coreappdata()->app_libpaths = 0;
#endif
}




QObject::~QObject()
{

...

qt_removeObject(this);
if (d->postedEvents)
QCoreApplication::removePostedEvents(this, 0);

if (d->parent) // remove it from parent object
d->setParent_helper(0);

d->threadData->deref();

#ifdef QT_JAMBI_BUILD
if (d->inEventHandler) {
qWarning("QObject: Do not delete object, '%s', during its event handler!",
objectName().isNull() ? "unnamed" : qPrintable(objectName()));
}
#endif
}

high_flyer
3rd January 2011, 14:09
No.
It is in your code.
your code defines QNodesScene, and it is your code which allocates it, and your code is deleting it - unless you are not deleting it, which might be the problem too, if you have some dangling pointers left.
So look in your code, where you have youe QNodeScene, and since it s node, I guess there are many of them in some containers, and probably, the problem is when the containers are being deleted.

this is your porblem:


pureStudio.exe!pureStudio::pgEditor::QNodesScene:: ~QNodesScene() Line 43 + 0x2e bytes C++
pureStudio.exe!pureStudio::pgEditor::QNodesScene:: `scalar deleting destructor'() + 0xf bytes C++

pl01
3rd January 2011, 14:14
Thanks for your answer,

But I never delete it myself ! Also, there is only one node, this one is "deleted" with removeItem and deleteLater before exiting the application ! (But the scene is never deleted !)

high_flyer
3rd January 2011, 14:15
The first option is giving QApplication as a parent.
If QNodesScene is a QObject (and it looks like it) then qApp will delete 'theInstance' when it gets deleted.
If for what ever reason 'theInstance' is not valid at the time qApp gets destroyed, then it will crash.

The second option doesn't give a parent, so you need to delete 'theInsrance' you self, and therefore qApp is not trying to delete it either.

And please post REAL code, since the devil is in details!

pl01
3rd January 2011, 14:25
Thanks for your help :-)

NB: it is real code :-P ;-)

high_flyer
3rd January 2011, 14:28
this (which you deleted in the mean while):


new theInstance = new QNodesScene(qApp);

new theInstance = new QNodesScene(0);



CAN'T be real code.