PDA

View Full Version : Active Qt: crash while unloading Qt Core DLL



ivigasin
6th March 2015, 02:59
Hi guys,

I have Qt (5.2.1) GUI application which I'm trying to expose as an ActiveX control. As usual after dll is built I call idc.exe to generate IDL. The problem is idc.exe always crashes on unloading QtCore.dll.

The main widget have some initialization/finalization code which is required for app to work. This code at some point create QRegEx object, which inside Qt leads to initializing QRegExpEngine and putting it to global static QCache hash.

Here is the stack trace:



Qt5Cored.dll!QGenericAtomicOps<QAtomicOpsBySize<4> >::load<long>(const long & _q_value) Line 96 C++
Qt5Cored.dll!QBasicAtomicInteger<int>::load() Line 142 C++
Qt5Cored.dll!QtPrivate::RefCount::deref() Line 66 C++
Qt5Cored.dll!QString::~QString() Line 921 C++
Qt5Cored.dll!QRegExpEngineKey::~QRegExpEngineKey() C++
Qt5Cored.dll!QHashNode<QRegExpEngineKey,QCache<QRegExpEngineKey,QRegExpEngine>::Node>::~QHashNode<QRegExpEngineKey,QCache<QRegExpEngineKey,QRegExpEngine>::Node>() C++
Qt5Cored.dll!QHashNode<QRegExpEngineKey,QCache<QRegExpEngineKey,QRegExpEngine>::Node>::`scalar deleting destructor'(unsigned int) C++
Qt5Cored.dll!QHash<QRegExpEngineKey,QCache<QRegExpEngineKey,QRegExpEngine>::Node>::deleteNode2(QHashData::Node * node) Line 544 C++
Qt5Cored.dll!QHashData::free_helper(void (QHashData::Node *) * node_delete) Line 423 C++
Qt5Cored.dll!QHash<QRegExpEngineKey,QCache<QRegExpEngineKey,QRegExpEngine>::Node>::freeData(QHashData * x) Line 590 C++
Qt5Cored.dll!QHash<QRegExpEngineKey,QCache<QRegExpEngineKey,QRegExpEngine>::Node>::~QHash<QRegExpEngineKey,QCache<QRegExpEngineKey,QRegExpEngine>::Node>() Line 301 C++
Qt5Cored.dll!QHash<QRegExpEngineKey,QCache<QRegExpEngineKey,QRegExpEngine>::Node>::clear() Line 596 C++
Qt5Cored.dll!QCache<QRegExpEngineKey,QRegExpEngine>::clear() Line 127 C++
Qt5Cored.dll!QCache<QRegExpEngineKey,QRegExpEngine>::~QCache<QRegExpEngineKey,QRegExpEngine>() Line 95 C++
Qt5Cored.dll!QCache<QRegExpEngineKey,QRegExpEngine>::`scalar deleting destructor'(unsigned int) C++
Qt5Cored.dll!``anonymous namespace'::Q_QGS_globalEngineCache::innerFunction '::`8'::Cleanup::~Cleanup() Line 3825 C++
Qt5Cored.dll!``anonymous namespace'::Q_QGS_globalEngineCache::innerFunction '::`9'::`dynamic atexit destructor for 'cleanup''() C++
Qt5Cored.dll!_CRT_INIT(void * hDllHandle, unsigned long dwReason, void * lpreserved) Line 416 C
Qt5Cored.dll!__DllMainCRTStartup(void * hDllHandle, unsigned long dwReason, void * lpreserved) Line 522 C
Qt5Cored.dll!_DllMainCRTStartup(void * hDllHandle, unsigned long dwReason, void * lpreserved) Line 472 C
ntdll.dll!776699a0() Unknown
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]
ntdll.dll!7767d702() Unknown
ntdll.dll!7767d5a4() Unknown
kernel32.dll!770279ed() Unknown
msvcr110.dll!__crtExitProcess(int status) Line 725 C
msvcr110.dll!doexit(int code, int quick, int retcaller) Line 627 C
msvcr110.dll!exit(int code) Line 395 C
idc.exe!00e32f73() Unknown
kernel32.dll!7702338a() Unknown
ntdll.dll!77669f72() Unknown
ntdll.dll!77669f45() Unknown



Any ideas?

Thank you!

Kind regards, Ivan

Grey DeMonstr
6th March 2015, 13:49
Your Qt5Cored.dll does not match your Qt5Ax* dlls. Make sure they are loaded from the same qt build.

ivigasin
6th March 2015, 19:23
Unfortunately that's not the cause. Qt5Ax* are static libraries, there are no dlls. I double checked there are only one version of Qt on the machine.

d_stranz
7th March 2015, 02:46
Are you sure you are linking all debug DLLs and static libraries? And that your Ax DLL itself is built as debug? Your stack trace shows that is is a debug version of Qt5Core DLL where the error occurs. You can't mix and match debug and release on Windows.

Another source of QString errors is mixing builds with wchar_t as a built-in type with wchar_t as a #defined name (/Zwchar_t vs /Zwchar_t-) compile-time options.

Grey DeMonstr
2nd April 2015, 11:58
Problem is solved. Reason was: QRegExp object was created from QStringLiteral string. So it is a static initialization order fiasco. QRegExp puts this string to its EngineCache (that is also static and is created earlier than the static string from QStringLiteral). So we came to EngineCache destructor when our static string is already destroyed.