Results 1 to 4 of 4

Thread: Qwt loaded from DLL - then unloaded and reloaded -> QVariant crashes (race cond?)

  1. #1
    Join Date
    Apr 2010
    Posts
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X

    Default 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

  2. The following user says thank you to hkhauke for this useful post:


  3. #2
    Join Date
    Apr 2010
    Posts
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X

    Default 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...
    Last edited by hkhauke; 2nd December 2013 at 21:31.

  4. The following user says thank you to hkhauke for this useful post:


  5. #3
    Join Date
    Apr 2013
    Posts
    63
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default 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?

  6. #4
    Join Date
    Feb 2018
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default 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.

Similar Threads

  1. 4.7.1 imageformats/qjpeg[d]4.dll unloaded
    By bmn in forum Installation and Deployment
    Replies: 2
    Last Post: 4th October 2011, 10:38
  2. Segmentation Fault after plugin was unloaded
    By zzz9 in forum Qt Programming
    Replies: 6
    Last Post: 3rd October 2011, 17:41
  3. Replies: 4
    Last Post: 4th January 2011, 13:07
  4. QList and QVariant crashes with VS2010
    By ZHawk in forum Qt Programming
    Replies: 4
    Last Post: 3rd January 2011, 14:33
  5. Compiling QT programs in Visual C++ 2008 by including batch files, reloaded projects
    By Meek the Geek in forum Installation and Deployment
    Replies: 6
    Last Post: 12th July 2010, 21:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.