[Qt-jambi-interest] Tracking down a problem in native-code

Tom Schindl listom at bestsolution.at
Fri Nov 7 16:36:38 CET 2008


Hi,

Well I now found how I can make my example not crash when I modify my
remove-method from:

> 	public void remove(ModelElement element) {
> 		System.err.println("Removing: " + element);
> 		QListWidgetItem item = findItem(element);
> 		if( item != null ) {
> 			((QListWidgetItemImpl)item).data = null;
> 			listWidget.removeItemWidget(item);
> 		}
> 	}

to

> 	public void remove(ModelElement element) {
> 		System.err.println("Removing: " + element);
> 		QListWidgetItem item = findItem(element);
> 		if( item != null ) {
> 			((QListWidgetItemImpl)item).data = null;
> 			item.dispose();
> 		}
> 	}

everything works. Looks like a the garbage collection is to working
appropriately. Is 2nd snippet correct, Gunnar? If yes this pops up a
question should I not rely on Java-GC and dispose QObject's myself all
the time to ensure a valid state?

I see this from the point of a library developer - What would you
suggest - should i dispose things explicitly when I don't need them any
more? What's better from a performance point of view, I guess dispose,
right because then the native resource is released immediately.

Tom

Tom Schindl schrieb:
> Gunnar Sletta schrieb:
>> Tom Schindl wrote:
>>> Hi Gunnar,
>>>
>>> The first thing I found out is that it looks like a problem in QList and
>>> Event-Listeners.
>>>
>>>> Thread 0 Crashed:
>>>> 0   <<00000000>>     0x26594a85 0 + 643385989
>>>> 1   libqtjambi.jnilib     0x0275367e qtjambi_event_notify(void**) + 80
>>>> 2   libQtCore.4.dylib     0x0896fd53
>>>> QInternal::activateCallbacks(QInternal::Callback, void**) + 115
>>>> 3   libQtCore.4.dylib     0x08a60b11
>>>> QCoreApplication::notifyInternal(QObject*, QEvent*) + 49
>>>> 4   libQtCore.4.dylib     0x08a63de1
>>>> QCoreApplicationPrivate::sendPostedEvents(QObject*, int,
>>>> QThreadData*) + 689
>>>> 5   libQtGui.4.dylib      0x08d4d68b
>>>> QEventDispatcherMac::processEvents(QFlags<QEventLoop::ProcessEventsFlag>)
>>>> + 107
>>>> 6   libQtCore.4.dylib     0x08a60231
>>>> QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) + 65
>>>> 7   libQtCore.4.dylib     0x08a602fd
>>>> QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) + 157
>>>> 8   libQtCore.4.dylib     0x08a64021 QCoreApplication::exec() + 161
>> I'm afraid not ;)
>>
>> This only states that the problem occured while an event was being
>> delivered, most likely it was a DeleteLater event, caused by a GUI
>> object being collected on the GC thread and the deletion being delegated
>> back to the GUI thread. We spent a lot of effort ironing out these
>> issues back in may, and I was rather confident that we had caught these
>> problems, but alas..
>>
>> Places to look:
>>  * Do you have any disposeLater() or dispose() in your code?
> 
> No dispose() / disposeLater() at all :-(
> 
>>  * Start looking at the parts of the app where you use temporary GUI
>> objects: QFonts, QPixmaps, QRegions, QGraphicsItems, QBrushes, QPens, etc.
>>
> 
> None of the above is used :-(
> 
> Another stacktrace I just got:
>> Thread 0 Crashed:
>> 0   libcom_trolltech_qt_gui.jnilib 	0x0982eedc qtjambi_destructor(void*) + 12
>> 1   libqtjambi.jnilib              	0x027547ef QtJambiDestructorEvent::callDestructor() + 57
>> 2   libqtjambi.jnilib              	0x0275367e qtjambi_event_notify(void**) + 80
>> 3   libQtCore.4.dylib              	0x0896fd53 QInternal::activateCallbacks(QInternal::Callback, void**) + 115
>> 4   libQtCore.4.dylib              	0x08a60b11 QCoreApplication::notifyInternal(QObject*, QEvent*) + 49
>> 5   libQtCore.4.dylib              	0x08a63de1 QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) + 689
>> 6   libQtGui.4.dylib               	0x08d4d68b QEventDispatcherMac::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) + 107
>> 7   libQtCore.4.dylib              	0x08a60231 QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) + 65
>> 8   libQtCore.4.dylib              	0x08a602fd QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) + 157
>> 9   libQtCore.4.dylib              	0x08a64021 QCoreApplication::exec() + 161
> 
> The problem occurs with some of my ListWidget-code because when I
> comment certain parts the crash is not happening any more.
> 
> E.g. when I comment the remove-code or the selection-update-code I don't
> get a crash.
> 
> The call order is like this:
> a) insert x items
> b) remove x old items
> c) clear the widget
> d) set a new selection
> 
> I tried to extract the call order but naturally then it doesn't crash.
> 
> 
> Tom
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Qt-jambi-interest mailing list
> Qt-jambi-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest




More information about the Qt-jambi-interest mailing list