PDA

View Full Version : Crash on deletion of QScriptEngine object



The_Fallen
10th March 2010, 21:05
Hi,

on start of my app I create a new QScriptEngine object, use it for a lot of stuff and destroy it before quitting the app. Unfortunately the app crashes when coming to the line with the delete.
I do so many things with the object during its lifetime, and I don't have any clue, what could be the reason for this. That's also why I can't post any source code here... Any ideas anybody? Thanks.

Cheers,
Tim

wysota
11th March 2010, 07:55
Please post the stack backtrace from the debugger.

The_Fallen
11th March 2010, 09:05
0 ~QObject qobject.cpp 954 0x6a20d95b
1 ~MainWindow mainwindow.cpp 166 0x00402d25
2 ~QObjectDelegate qscriptqobject.cpp 1156 0x0a5d2f70
3 ~Data qscriptobject.cpp 42 0x0a5cadea
4 ~QScriptObject qscriptobject.cpp 52 0x0a5caf11
5 QTJSC::Heap::sweep<(QTJSC::HeapType)0> Collector.cpp 1156 0x0a614e8f
6 QTJSC::Heap::destroy Collector.cpp 199 0x0a5530f7
7 ~QScriptEnginePrivate qscriptengine.cpp 838 0x0a5b6277
8 QScopedPointerDeleter<QObjectData>::cleanup qscopedpointer.h 62 0x6a267efe
9 ~QScopedPointer qscopedpointer.h 100 0x6a25e701
10 ~QObject qobject.cpp 992 0x6a20cfd0
11 ~QScriptEngine qscriptengine.cpp 1488 0x0a5b8d94
12 ~MainWindow mainwindow.cpp 166 0x00402a75
13 qMain main.cpp 9 0x0040140d
14 WinMain@16 qtmain_win.cpp 131 0x0046da72
15 main 0 0x0046d798

Looking at this again I had an idea...
As you can see, the destructor of MainWindow appears twice in the stack backtrace. Then I realized that I'm wrapping the MainWindow object in a ScriptValue:


QScriptValue scriptMainWnd = engine->newQObject(mainWnd, QScriptEngine::ScriptOwnership);

Does the destructor of QScriptEngine also delete all the objects connected to its QScriptValues? Then of course this would make perfect sense, since the destruction of the QScriptEngine would yield the destruction of the MainWindow. But that's just a wild guess...

Cheers,
Tim

wysota
11th March 2010, 09:21
Does the destructor of QScriptEngine also delete all the objects connected to its QScriptValues?
If you add them with script ownership then yes.

The_Fallen
11th March 2010, 09:27
Yes, I'm stupid... If I change the ownership to QtOwnership, everything works fine. Thanks a lot! :-)