Results 1 to 12 of 12

Thread: QGLWidget bug

  1. #1
    Join Date
    Aug 2007
    Location
    Russia
    Posts
    19
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question QGLWidget bug

    I think we have the bug in OpenGL texture engine. I’ve write application. It draws simple filled rectangle in separate thread, and then pushes image into main windows event loop through signal/slot system. Main widget requests thread to render new image every timer tick. After some time passed, it crashes deep into Qt core.

    But, if you uncomment 2 lines in source code and compile/run it again, it will work perfectly! This lines changes inheritance to QWidget instead of QGLWidget.

    Qt Code:
    1. //class OpenGLHashBug: public QWidget
    2. class OpenGLHashBug: public QGLWidget
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. //OpenGLHashBug::OpenGLHashBug(QWidget *parent, Qt::WFlags flags): QWidget(parent)
    2. OpenGLHashBug::OpenGLHashBug(QWidget *parent, Qt::WFlags flags): QGLWidget(parent)
    To copy to clipboard, switch view to plain text mode 

    I think bug is near synchronization of QHashMap for OpenGL textures...

    What do you think about it? Is it my mistake or not?


    P.S. Sorry for my bad English…
    Attached Files Attached Files

  2. #2
    Join Date
    Aug 2007
    Location
    Russia
    Posts
    19
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget bug

    Qt version: 4.3.1, compiled with Visual Studio 2005 SP1 under Vista x86-32, nv7800GTX video
    I've just tested it on my notebook. Application crashes on XP SP2 + Qt 4.3.0 too...
    Last edited by Wizard; 30th August 2007 at 19:01. Reason: updated contents

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget bug

    I've let it running for 30 minutes on Linux with Qt 4.3.0 and it didn't crash. So it might be a windows-only problem.
    Last edited by jacek; 31st August 2007 at 01:26. Reason: corrected Qt version (was 4.3.1)

  4. #4
    Join Date
    Aug 2007
    Location
    Russia
    Posts
    19
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget bug

    In Debug version or Release? I've found that Release version just randomly destroys heap and crashes when closing application... Debug version of Microsoft CRT marks freed memory by setting it by 0xfeeefeee, and I see access by this freed pointer.
    You have tested it on multicore processor?
    I haven't singlecore processors and couple of minutes is enough to crash the application...
    Last edited by Wizard; 30th August 2007 at 21:14. Reason: updated contents

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget bug

    Quote Originally Posted by Wizard View Post
    In Debug version or Release?
    Both.

    Quote Originally Posted by Wizard View Post
    I've found that Release version just randomly destroys heap and crashes when closing application...
    Maybe Dr Watson/Dr Mingw will help to locate the method that tries to do that?

    Quote Originally Posted by Wizard View Post
    You have tested it on multicore processor?
    Yes.

  6. #6
    Join Date
    Aug 2007
    Location
    Russia
    Posts
    19
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget bug

    Quote Originally Posted by jacek View Post
    Maybe Dr Watson/Dr Mingw will help to locate the method that tries to do that?
    Yes.
    I know that method )
    Output:
    First-chance exception at 0x67054768 (QtCored4.dll) in OpenGLHashBug.exe: 0xC0000005: Access violation reading location 0xfeeefeee.
    Unhandled exception at 0x67054768 (QtCored4.dll) in OpenGLHashBug.exe: 0xC0000005: Access violation reading location 0xfeeefeee.

    Call stack:
    QtCored4.dll!QHashData::nextNode(QHashData::Node * node=0x0114d420) Line 203 + 0x3 bytes QtOpenGLd4.dll!QHash<QString,QCache<QString,QGLTex ture>::Node>::const_iterator:perator++() Line 372 + 0xc bytes
    QtOpenGLd4.dll!QHash<QString,QCache<QString,QGLTex ture>::Node>::keys() Line 603
    QtOpenGLd4.dll!QCache<QString,QGLTexture>::keys() Line 89 + 0x1f bytes
    QtOpenGLd4.dll!qt_gl_clean_cache(const QString & cacheKey={...}) Line 1606 + 0xf bytes
    QtOpenGLd4.dll!qt_gl_image_cleanup(__int64 key=0x0000005900000000) Line 1626 + 0x39 bytes
    QtGuid4.dll!QImage::detach() Line 1303 + 0x10 bytes
    QtGuid4.dll!QPainter::begin(QPaintDevice * pd=0x04edff2c) Line 1286
    QtGuid4.dll!QPainter::QPainter(QPaintDevice * pd=0x04edff2c) Line 1056
    OpenGLHashBug.exe!ImageRenderer::run() Line 81 + 0xd bytes
    QtCored4.dll!QThreadPrivate::start(void * arg=0x01132770) Line 220
    msvcr80d.dll!_callthreadstartex() Line 348 + 0xf bytes
    msvcr80d.dll!_threadstartex(void * ptd=0x0114afd0) Line 331

    Function in qhash.cpp:
    ...

    Qt Code:
    1. QHashData::Node *QHashData::nextNode(Node *node)
    2. {
    3. union {
    4. Node *next;
    5. Node *e;
    6. QHashData *d;
    7. };
    8. next = node->next;
    9. Q_ASSERT_X(next, "QHash", "Iterating beyond end()");
    10. if (next->next) // <<-- Error is here
    11. return next;
    12.  
    13. int start = (node->h % d->numBuckets) + 1;
    14. Node **bucket = d->buckets + start;
    15. int n = d->numBuckets - start;
    16. while (n--) {
    17. if (*bucket != e)
    18. return *bucket;
    19. ++bucket;
    20. }
    21. return e;
    22. }
    To copy to clipboard, switch view to plain text mode 

    Sometimes I have another call stack:
    QtCored4.dll!q_atomic_increment(volatile int * ptr=0xfeeefeee) Line 149 + 0xb bytes
    QtCored4.dll!QBasicAtomic::ref() Line 73 + 0x10 bytes
    QtCored4.dll!QString::QString(const QString & other={...}) Line 648 + 0x3e bytes
    QtOpenGLd4.dll!QList<QString>::append(const QString & t={...}) Line 402 + 0xd bytes
    QtOpenGLd4.dll!QHash<QString,QCache<QString,QGLTex ture>::Node>::keys() Line 602
    QtOpenGLd4.dll!QCache<QString,QGLTexture>::keys() Line 89 + 0x1f bytes
    QtOpenGLd4.dll!qt_gl_clean_cache(const QString & cacheKey={...}) Line 1606 + 0xf bytes
    QtOpenGLd4.dll!qt_gl_image_cleanup(__int64 key=0x0000010100000000) Line 1626 + 0x39 bytes
    QtGuid4.dll!QImage::detach() Line 1303 + 0x10 bytes
    QtGuid4.dll!QPainter::begin(QPaintDevice * pd=0x04faff2c) Line 1286
    ....

    and another one exception in near that place:
    First-chance exception at 0x67054768 (QtCored4.dll) in OpenGLHashBug.exe: 0xC0000005: Access violation reading location 0x00000001. // <<-- Access in freed pointer (0x00000000) + 1, e.g. freed object/structure.
    Call stack:
    QHashData::nextNode(QHashData::Node * node=0x01c36a28) Line 203 + 0x3 bytes
    QHash<QString,QCache<QString,QGLTexture>::Node>::c onst_iterator:perator++() Line 372 + 0xc bytes
    QHash<QString,QCache<QString,QGLTexture>::Node>::k eys() Line 603
    QCache<QString,QGLTexture>::keys() Line 89 + 0x1f bytes
    qt_gl_clean_cache(const QString & cacheKey={...}) Line 1606 + 0xf bytes
    qt_gl_image_cleanup(__int64 key=0x000002f600000000) Line 1626 + 0x39 bytes
    QImage::detach() Line 1303 + 0x10 bytes
    QPainter::begin(QPaintDevice * pd=0x0500ff2c) Line 1286
    QPainter::QPainter(QPaintDevice * pd=0x0500ff2c) Line 1056
    ImageRenderer::run() Line 81 + 0xd bytes
    QThreadPrivate::start(void * arg=0x01c02770) Line 220

    That's why is think that Image::detach() method is not protected by mutex
    Last edited by Wizard; 30th August 2007 at 22:53.

  7. #7
    Join Date
    Aug 2007
    Location
    Russia
    Posts
    19
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget bug

    I have installed openSUSE in VMWare with Qt 4.3.1. First time I think that there was no bugs... But if you will drag, resize, click, move mouse (use application) you will have segmentation fault error...
    I've changed source in that way.
    Qt Code:
    1. startTimer(0);
    To copy to clipboard, switch view to plain text mode 

    Call stack:
    11 QHashData::nextNode() /home/wizard/qt-x11-opensource-src-4.3.1/src/corelib/tools/qhash.cpp:220 0xb735bbad
    10 QHash<QString, QCache<QString, QGLTexture>::Node>::keys() /home/wizard/qt-x11-opensource-src-4.3.1/src/corelib/tools/qhash.h:389 0xb7ed8102
    9 qt_gl_clean_cache() /home/wizard/qt-x11-opensource-src-4.3.1/src/corelib/tools/qcache.h:106 0xb7ed69f5
    8 qt_gl_image_cleanup() /home/wizard/qt-x11-opensource-src-4.3.1/src/opengl/qgl.cpp:1643 0xb7ed6c7b
    7 QImage::detach() /home/wizard/qt-x11-opensource-src-4.3.1/src/gui/image/qimage.cpp:1320 0xb788f144
    6 QPainter::begin() /home/wizard/qt-x11-opensource-src-4.3.1/src/gui/painting/qpainter.cpp:1301 0xb78daeff
    5 QPainter() /home/wizard/qt-x11-opensource-src-4.3.1/src/gui/painting/qpainter.cpp:1072 0xb78ddfb5
    4 ImageRenderer::run() /home/wizard/workspace/GLTest/gltest.cpp:70 0x0804abfa
    3 QThreadPrivate::start() /home/wizard/qt-x11-opensource-src-4.3.1/src/corelib/thread/qthread_unix.cpp:181 0xb7342c62
    2 start_thread() 0xb7166112
    1 clone() 0xb6fdb2ee

    Qt Code:
    1. if (next->next) // <<-- Segmentation fault
    2. return next;
    To copy to clipboard, switch view to plain text mode 

    P.S. It is difficult to explain what I mean )) I badly know english, online translators works very-very-very bad... Try to understand ) Together we will find solution!
    Last edited by Wizard; 30th August 2007 at 23:41.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget bug

    Quote Originally Posted by Wizard View Post
    I have installed openSUSE in VMWare with Qt 4.3.1. First time I think that there was no bugs... But if you will drag, resize, click, move mouse (use application) you will have segmentation fault error...
    I've tried resizing, clicking and moving the window, but it didn't crash.

    Quote Originally Posted by Wizard View Post
    QImage::detach() /home/wizard/qt-x11-opensource-src-4.3.1/src/gui/image/qimage.cpp:1320 0xb788f144
    6 QPainter::begin() /home/wizard/qt-x11-opensource-src-4.3.1/src/gui/painting/qpainter.cpp:1301 0xb78daeff
    Hmm... these two methods are always present in the backtrace. What happens if you change the code this way:
    Qt Code:
    1. painter.fillRect(0, 0, 50, 50, QColor(qrand()));
    2. painter.end(); // <-------
    3.  
    4. emit ImageReady(MyImage);
    To copy to clipboard, switch view to plain text mode 
    ?

  9. #9
    Join Date
    Aug 2007
    Location
    Russia
    Posts
    19
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget bug

    What happens if you change the code this way:
    Qt Code:
    1. painter.fillRect(0, 0, 50, 50, QColor(qrand()));
    2. painter.end(); // <-------
    3.  
    4. emit ImageReady(MyImage);
    To copy to clipboard, switch view to plain text mode 
    ?
    The same bug. First, QPainter::end() was called automatically. Second, bug is near OpenGL, because after changing inheritance to QWidget all works...

  10. #10
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGLWidget bug

    This looks like a bug to me.
    It seems qt_gl_clean_cache() isn't reentrant since it accessess the
    static QGLTextureCache *qt_tex_cache(qgl.cpp) without trying to protect it with a mutex. They don't even use the QGLOBALSTATIC macro. You should submit a bug report.

  11. The following user says thank you to spud for this useful post:

    Wizard (31st August 2007)

  12. #11
    Join Date
    Aug 2007
    Location
    Russia
    Posts
    19
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget bug

    May be they don't use it for performance reasons? I send bug report to Trolltech...
    Thanks for advice )
    Last edited by Wizard; 31st August 2007 at 10:08. Reason: spelling error

  13. #12
    Join Date
    Aug 2007
    Location
    Russia
    Posts
    19
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Lightbulb Re: QGLWidget bug

    I've designed some workaround for this bug ) Just half an hour was enough...
    Attached Files Attached Files

Similar Threads

  1. Transparent window with QGLWidget
    By ultr in forum Qt Programming
    Replies: 4
    Last Post: 28th April 2008, 07:01
  2. why linking problem with QGLWidget???
    By Shuchi Agrawal in forum Newbie
    Replies: 17
    Last Post: 16th March 2007, 10:45
  3. Transparent QWidget on QGLWidget
    By showhand in forum Qt Programming
    Replies: 2
    Last Post: 27th November 2006, 01:00
  4. QGLWidget on another QGLWiget
    By showhand in forum Qt Programming
    Replies: 1
    Last Post: 23rd October 2006, 09:59
  5. QGLWidget with multiple monitors
    By Rayven in forum Qt Programming
    Replies: 3
    Last Post: 4th August 2006, 10:28

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.