Qwt loaded from DLL - then unloaded and reloaded -> QVariant crashes (race cond?)
Hi,
I have a program which is based on QT and runs the QApplication. Now, I load a widget from a DLL which uses two QwtPlotCurve objects.
Hence, internally, I use a QwtLegendData object somewhere which belongs to the loaded DLL. Everything is fine so far.
Now, I unload the DLL and reload it afterwards. When trying to attach the curves in the newly loaded DLL, the application crashes.
I have isolated the problem up to a certain point but would like to discuss it here:
By browsing the call stack, I find that the problem is deep inside QT in the handling of the creation of a QVariant:
It seems that Qwt added a specific QVariant type together with a callback for object creation, presumably
in the Qwt initialization phase. In my case - the associated object type is a QwtLegendData object.
For this object type, the Qvariant and associated creation function are, e.g., employed in the function
call QwtPlotItem::legendData() by calling qVariantSetValue(...).
The problem seems to arise from the associated callback for object creation as stored with the
QVariant: It was added initially when the DLL was loaded for the first time but now -as the DLL was unloaded and reloaded -
it is no longer valid: As soon as I unload the DLL the main application still operates and does not de-reference the QVariant callback for creation,
and when reloading the DLL, it seems that the callback function pointer is sometimes updated properly, sometimes not.
If not, Qt points to the old symbol which is no longer valid since the DLL was unloaded and when calling the creator function for the first time
given the newly loaded DLL, the invalid old symbol stored for the QVariant type leads to the crash.
I have the feeling that this is due to a race condition: the QVariant initialization code happens in the "dll load" thread
whereas the allocation functionality happens in the "QT thread". A sleep of 1 sec right before the call to the QWT functions seems
to solve the issue..
Could anyone confirm this behavior? Is there a limitation for using Qwt widgets allocated in DLLs which may be unloaded during runtime?
Note that this did happen on a system Visual Studio 2012, Qwt 6.1.0 and Qt5 whereas on a system with Visual Studio 2010, Qwt 6.0.2 and Qt5,
the problem does not occur.
Thank you in advance and best regards
Hauke
Re: Qwt loaded from DLL - then unloaded and reloaded -> QVariant crashes (race cond?)
mmh, I start to get the feeling that this is more a QT5 bug than a problem related to qwt.
And i need to correct: the datatype which is stored as a QVariant is a QwtText object rather than a QwtLegendData. But still, it crashes.
Here is the callstack:
337961bd() Unknown
[Frames below may be incorrect and/or missing]
Qt5Cored.dll!QMetaType::create(const void * copy) Line 938 C++
Qt5Cored.dll!`anonymous namespace'::customConstruct(QVariant::Private * d, const void * copy) Line 830 C++
> Qt5Cored.dll!QVariant::create(int type, const void * copy) Line 1124 C++
Qt5Cored.dll!QVariant::QVariant(int typeId, const void * copy, unsigned int flags) Line 1452 C++
qwtvc110qt5d.dll!qVariantSetValue<QwtText>(QVarian t & v, const QwtText & t) Line 507 C++
qwtvc110qt5d.dll!QwtPlotItem::legendData() Line 603 C++
337961bd is the address where the processor expects the QVariant creator function - which seems to not be correct.
And here is where the problem arises, file qmetatype.cpp which is part of QtCore in Qt5, function
int QMetaType::registerNormalizedType(const NS(QByteArray) &normalizedTypeName, Deleter deleter,
Creator creator,
Destructor destructor,
Constructor constructor,
int size, TypeFlags flags, const QMetaObject *metaObject)
If the QMetaType registration (file qwt_text.h, line "Q_DECLARE_METATYPE( QwtText )") is called for the second time with the same type id (which happens once the dll is loaded for the second time) a possibly updated creator seems to be ignored.
By the way, I have to correct that the problem did not occur with Qwt 6.0.2 combined with Qt4 in my first mail...
Re: Qwt loaded from DLL - then unloaded and reloaded -> QVariant crashes (race cond?)
HI,
I am facing the same issue. Are you able to resolve it?
Re: Qwt loaded from DLL - then unloaded and reloaded -> QVariant crashes (race cond?)
I am also facing the same issue. I am using qwt 6.1.2 built on Qt5.3.2 in VS 2012.