Results 1 to 4 of 4

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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:


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, 09:38
  2. Segmentation Fault after plugin was unloaded
    By zzz9 in forum Qt Programming
    Replies: 6
    Last Post: 3rd October 2011, 16:41
  3. Replies: 4
    Last Post: 4th January 2011, 12:07
  4. QList and QVariant crashes with VS2010
    By ZHawk in forum Qt Programming
    Replies: 4
    Last Post: 3rd January 2011, 13: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, 20: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.