Qt-jambi-interest Archive, March 2007
custom ItemDelegate crashes (sometimes)
Message 1 in thread
Hi all
- customer ItemDelegat
Sometimes (but I can't reproduce it) after finishing my testapplication
I receive the following message:
b) -> QObjects can only be implicitly garbage collected when owned
by a QThread, native resource ('' [QItemDelegate]) is leaked
Sometimes the application crashes just a few seconds after launching the
programm (and sometimes not) and sometimes it works fine.
(there a three scenarios with the same source - code))
a) ok
b) message
c) crash
c) -> hs_err_pid780.log
I implementet my own ItemDelegate because I found no other way to change
the item height. The source code looks like that
-------------------------------------------------------------
public class MyItemDelegate extends QItemDelegate {
/**
* Konstruktor
*/
public MyItemDelegate() {
super();
}
/**
* @see com.trolltech.qt.gui.QItemDelegate
* #sizeHint(com.trolltech.qt.gui.QStyleOptionViewItem,
* com.trolltech.qt.core.QModelIndex)
*/
@Override
public QSize sizeHint(QStyleOptionViewItem option,
QModelIndex modelindex) {
return new QSize(120,22);
}
}
// ... and within the Model
// ... there is only one model per view
void SetView(QAbstractItemView view) {
m_view = view;
m_view.setModel(this);
// resizeEvent - resize the columns
m_view.installEventFilter(this);
// itemheight - sizeHint
if (QTreeView.class.isInstance(m_view)) {
// this code sometimes forces a crash
m_view.setItemDelegate(new MyItemDelegate());
}
}
-------------------------------------------------------------
I could avoid the crash and the message by comment:
// m_view.setItemDelegate..
Greetings Arne
#
#
# An unexpected error has been detected by Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0b3a1f1c, pid=780, tid=3252
#
# Java VM: Java HotSpot(TM) Client VM (1.6.0-b105 mixed mode)
# Problematic frame:
# C [com_trolltech_qt_gui.dll+0xb1f1c]
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#
--------------- T H R E A D ---------------
Current thread (0x00386c00): JavaThread "main" [_thread_in_native, id=3252]
siginfo: ExceptionCode=0xc0000005, reading address 0x00000000
Registers:
EAX=0x00000000, EBX=0x0b19e618, ECX=0x00386ce8, EDX=0x6d9c5e60
ESP=0x003ed6c8, EBP=0x0b126d60, ESI=0x00386ce8, EDI=0x00000000
EIP=0x0b3a1f1c, EFLAGS=0x00010246
Top of Stack: (sp=0x003ed6c8)
0x003ed6c8: 00386ce8 00000000 00386ce8 00386ce8
0x003ed6d8: 00000000 0b126d60 0b133330 0b133328
0x003ed6e8: 00000000 0b154d38 003ed7c0 ffffffff
0x003ed6f8: 652c95ce 003ed750 003ed758 003ed720
0x003ed708: 0b154d10 0b154d38 00000005 00000000
0x003ed718: ffffffff 00000000 00000000 00000000
0x003ed728: 00000000 00000000 00000003 10007d01
0x003ed738: 10007d19 003ed750 ffffffff ffffffff
Instructions: (pc=0x0b3a1f1c)
0x0b3a1f0c: ff 15 3c 64 44 0b 57 56 ff 15 20 64 44 0b 8b 16
0x0b3a1f1c: 8b 38 8b 58 04 83 c4 20 6a 00 56 ff 52 50 8b 44
Stack: [0x003a0000,0x003f0000), sp=0x003ed6c8, free space=309k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [com_trolltech_qt_gui.dll+0xb1f1c]
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j com.trolltech.qt.gui.QApplication.exec()I+0
j kunden.Verwaltung.main([Ljava/lang/String;)V+56
v ~StubRoutines::call_stub
--------------- P R O C E S S ---------------
Java Threads: ( => current thread )
0x0b118800 JavaThread "db4o WeakReference collector" daemon [_thread_blocked, id=1700]
0x0b041400 JavaThread "Thread-0" daemon [_thread_blocked, id=3356]
0x0aaa1800 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=3376]
0x0aaa1400 JavaThread "CompilerThread0" daemon [_thread_blocked, id=3368]
0x0aa94000 JavaThread "JDWP Command Reader" daemon [_thread_in_native, id=3748]
0x0aa92c00 JavaThread "JDWP Event Helper Thread" daemon [_thread_blocked, id=3276]
0x0aa90c00 JavaThread "JDWP Transport Listener: dt_socket" daemon [_thread_blocked, id=172]
0x0aa85c00 JavaThread "Attach Listener" daemon [_thread_blocked, id=3072]
0x0aa85000 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=3348]
0x0aa77400 JavaThread "Finalizer" daemon [_thread_blocked, id=2636]
0x0aa73000 JavaThread "Reference Handler" daemon [_thread_blocked, id=3372]
=>0x00386c00 JavaThread "main" [_thread_in_native, id=3252]
Other Threads:
0x0aa6fc00 VMThread [id=3060]
0x0aabc400 WatcherThread [id=3616]
VM state:not at safepoint (normal execution)
VM Mutex/Monitor currently owned by a thread: None
Heap
def new generation total 960K, used 224K [0x02960000, 0x02a60000, 0x02e40000)
eden space 896K, 17% used [0x02960000, 0x02988230, 0x02a40000)
from space 64K, 100% used [0x02a40000, 0x02a50000, 0x02a50000)
to space 64K, 0% used [0x02a50000, 0x02a50000, 0x02a60000)
tenured generation total 4096K, used 927K [0x02e40000, 0x03240000, 0x06960000)
the space 4096K, 22% used [0x02e40000, 0x02f27e28, 0x02f28000, 0x03240000)
compacting perm gen total 12288K, used 6726K [0x06960000, 0x07560000, 0x0a960000)
the space 12288K, 54% used [0x06960000, 0x06ff1870, 0x06ff1a00, 0x07560000)
No shared spaces configured.
Dynamic libraries:
0x00400000 - 0x00423000 C:\Programme\Java\jre1.6.0\bin\javaw.exe
0x7c910000 - 0x7c9c7000 C:\WINDOWS\system32\ntdll.dll
0x7c800000 - 0x7c906000 C:\WINDOWS\system32\kernel32.dll
0x77da0000 - 0x77e4a000 C:\WINDOWS\system32\ADVAPI32.dll
0x77e50000 - 0x77ee1000 C:\WINDOWS\system32\RPCRT4.dll
0x77d10000 - 0x77da0000 C:\WINDOWS\system32\USER32.dll
0x77ef0000 - 0x77f37000 C:\WINDOWS\system32\GDI32.dll
0x7c340000 - 0x7c396000 C:\Programme\Java\jre1.6.0\bin\msvcr71.dll
0x6d7c0000 - 0x6da07000 C:\Programme\Java\jre1.6.0\bin\client\jvm.dll
0x76af0000 - 0x76b1e000 C:\WINDOWS\system32\WINMM.dll
0x6d310000 - 0x6d318000 C:\Programme\Java\jre1.6.0\bin\hpi.dll
0x76bb0000 - 0x76bbb000 C:\WINDOWS\system32\PSAPI.DLL
0x6d400000 - 0x6d429000 C:\Programme\Java\jre1.6.0\bin\jdwp.dll
0x6d6c0000 - 0x6d6c6000 C:\Programme\Java\jre1.6.0\bin\npt.dll
0x6d770000 - 0x6d77c000 C:\Programme\Java\jre1.6.0\bin\verify.dll
0x6d3b0000 - 0x6d3cf000 C:\Programme\Java\jre1.6.0\bin\java.dll
0x6d7b0000 - 0x6d7bf000 C:\Programme\Java\jre1.6.0\bin\zip.dll
0x6d280000 - 0x6d287000 C:\Programme\Java\jre1.6.0\bin\dt_socket.dll
0x71a10000 - 0x71a27000 C:\WINDOWS\system32\WS2_32.dll
0x77be0000 - 0x77c38000 C:\WINDOWS\system32\msvcrt.dll
0x71a00000 - 0x71a08000 C:\WINDOWS\system32\WS2HELP.dll
0x719b0000 - 0x719f0000 C:\WINDOWS\System32\mswsock.dll
0x76ee0000 - 0x76f07000 C:\WINDOWS\system32\DNSAPI.dll
0x76f70000 - 0x76f78000 C:\WINDOWS\System32\winrnr.dll
0x76f20000 - 0x76f4d000 C:\WINDOWS\system32\WLDAP32.dll
0x6f790000 - 0x6f79f000 C:\WINDOWS\system32\pnrpnsp.dll
0x76f80000 - 0x76f86000 C:\WINDOWS\system32\rasadhlp.dll
0x66710000 - 0x66769000 C:\WINDOWS\system32\hnetcfg.dll
0x719f0000 - 0x719f8000 C:\WINDOWS\System32\wshtcpip.dll
0x67000000 - 0x67167000 C:\Entwickler\eclipse\qtjambi-win\bin\QtCore4.dll
0x774b0000 - 0x775ec000 C:\WINDOWS\system32\ole32.dll
0x7c3a0000 - 0x7c41b000 C:\WINDOWS\system32\MSVCP71.dll
0x65000000 - 0x65551000 C:\Entwickler\eclipse\qtjambi-win\bin\QtGui4.dll
0x76350000 - 0x7639a000 C:\WINDOWS\system32\comdlg32.dll
0x77f40000 - 0x77fb6000 C:\WINDOWS\system32\SHLWAPI.dll
0x5d450000 - 0x5d4e7000 C:\WINDOWS\system32\COMCTL32.dll
0x7c9d0000 - 0x7d1ee000 C:\WINDOWS\system32\SHELL32.dll
0x770f0000 - 0x7717c000 C:\WINDOWS\system32\OLEAUT32.dll
0x76330000 - 0x7634d000 C:\WINDOWS\system32\IMM32.dll
0x72f70000 - 0x72f96000 C:\WINDOWS\system32\WINSPOOL.DRV
0x773a0000 - 0x774a2000 C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9\comctl32.dll
0x10000000 - 0x10023000 C:\Entwickler\eclipse\qtjambi-win\bin\qtjambi.dll
0x0b220000 - 0x0b29d000 C:\Entwickler\eclipse\qtjambi-win\bin\com_trolltech_qt_core.dll
0x0b2f0000 - 0x0b60c000 C:\Entwickler\eclipse\qtjambi-win\bin\com_trolltech_qt_gui.dll
0x5b0f0000 - 0x5b128000 C:\WINDOWS\system32\uxtheme.dll
0x6d570000 - 0x6d583000 C:\Programme\Java\jre1.6.0\bin\net.dll
0x590b0000 - 0x590b7000 C:\WINDOWS\System32\wship6.dll
0x6d590000 - 0x6d599000 C:\Programme\Java\jre1.6.0\bin\nio.dll
0x75790000 - 0x757fb000 C:\WINDOWS\system32\usp10.dll
VM Arguments:
jvm_args: -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:1300
java_command: kunden.Verwaltung
Launcher Type: SUN_STANDARD
Environment Variables:
CLASSPATH=C:\Entwickler\eclipse\qtjambi-win
PATH=C:\Entwickler\eclipse\qtjambi-win\bin
USERNAME=Arne Stocker
OS=Windows_NT
PROCESSOR_IDENTIFIER=x86 Family 6 Model 13 Stepping 6, GenuineIntel
--------------- S Y S T E M ---------------
OS: Windows XP Build 2600 Service Pack 2
CPU:total 1 family 6, cmov, cx8, fxsr, mmx, sse, sse2
Memory: 4k page, physical 514480k(85336k free), swap 1256356k(862588k free)
vm_info: Java HotSpot(TM) Client VM (1.6.0-b105) for windows-x86, built on Nov 29 2006 00:48:48 by "java_re" with unknown MS VC++:1310
Message 2 in thread
Arne Stocker wrote:
> Hi all
>
> - customer ItemDelegat
>
> Sometimes (but I can't reproduce it) after finishing my testapplication
> I receive the following message:
>
> b) -> QObjects can only be implicitly garbage collected when owned
> by a QThread, native resource ('' [QItemDelegate]) is leaked
The problem is that your item delegate is being garbage collected. You
need to keep a reference to it. We're investigating methods for making
this requirement more explicit, so that mistakes such as this doesn't
happen.
One way to solve this is to give the delegate a parent. QItemDelegate
has an overloaded constructor which takes a QObject parent. All QObject
subclasses has a constructor like this and if an object has a parent, it
will be memory managed by the parent, and thus, kept alive.
Alternativly, you keep a reference to your item delegate subclass in the
instance that uses it.
> Sometimes the application crashes just a few seconds after launching the
> programm (and sometimes not) and sometimes it works fine.
> (there a three scenarios with the same source - code))
>
> a) ok
> b) message
> c) crash
>
> c) -> hs_err_pid780.log
>
> I implementet my own ItemDelegate because I found no other way to change
> the item height. The source code looks like that
One of the available roles in the Qt.ItemDataRole is SizeHintRole. Could
this maybe help you?
---
What happens internally in Qt here is that when an item delegate is
deleted the pointer in the view to the delegate is reset to 0, so it
should be safe, but since it crashes, that means its a missing safty
check. Could you please supply me with some info to reproduce this or
maybe an example so I can investigate this bug?
best regards,
Gunnar
Message 3 in thread
Hi Gunnar
> One of the available roles in the Qt.ItemDataRole is SizeHintRole. Could this maybe help you?
Ok, that works fine. I hat allready tried to use it, but first I
returned a new Integer(22) instead of new QSize(120,22).
> All QObject subclasses has a constructor like this and if an object has a parent, it will be memory managed by the parent, and thus, kept alive.
That works either. Thank you.
> Could you please supply me with some info to reproduce this or maybe an example so I can investigate this bug?
I will try to extract the problem
best regards
Arne