[Interest] Odd crash with QPainter + QOpenGLWidget

Matthew Woehlke mwoehlke.floss at gmail.com
Thu Mar 28 17:11:18 CET 2019

On 27/03/2019 21.05, Thiago Macieira wrote:
> On Wednesday, 27 March 2019 14:48:16 PDT Matthew Woehlke wrote:
>> ==12997==    by 0x598A728: QOpenGLVertexArrayObjectPrivate::destroy()
>> (qopenglvertexarrayobject.cpp:212)
> [...]
>> ==12997==  Address 0x8 is not stack'd, malloc'd or (recently) free'd
> Line 212:
>         if (QThread::currentThread() != qGuiApp->thread()) {
> There is a pointer being dereferenced on that line: qGuiApp, which is:
> #define qGuiApp (static_cast<QGuiApplication *>(QCoreApplication::instance()))
> That means you're somehow running this code after the application object was 
> destroyed. Your backtrace wasn't long enough to tell where this was being 
> called from (run valgrind with --num-callers=20), but my guess is that it's a 
> global destructor keyed to the font engine.
> But I also don't see how this could be *your* fault. If you can get the full 
> backtrace, I think you should report as a bug.

Here's the full trace:

==1742== Invalid read of size 8
==1742==    at 0x5D1F4E4: QObject::thread() const (qobject.cpp:1420)
==1742==    by 0x5989728: QOpenGLVertexArrayObjectPrivate::destroy()
==1742==    by 0x59899AA:
==1742==    by 0x5986286:
==1742==    by 0x59862AC:
==1742==    by 0x5769DAB: ~QLinkedListNode (qlinkedlist.h:69)
==1742==    by 0x5769DAB:
[clone .isra.119] (qlinkedlist.h:345)
==1742==    by 0x5BB00E8: QHashData::free_helper(void
(*)(QHashData::Node*)) (qhash.cpp:572)
==1742==    by 0x57699BA: freeData (qhash.h:585)
==1742==    by 0x57699BA: ~QHash (qhash.h:254)
==1742==    by 0x57699BA: QFontEngine::~QFontEngine() (qfontengine.cpp:271)
==1742==    by 0x18C145FC: QFontEngineFT::~QFontEngineFT()
==1742==    by 0x5769AE4: QFontEngineMulti::~QFontEngineMulti()
==1742==    by 0x18C1D41C:
==1742==    by 0x575E25E: QFontCache::clear() (qfont.cpp:2796)
==1742==    by 0x575E516: QFontCache::~QFontCache() (qfont.cpp:2752)
==1742==    by 0x575E5CC: QFontCache::~QFontCache() (qfont.cpp:2753)
==1742==    by 0x5B62ED8: QThreadStorageData::set(void*)
==1742==    by 0x56BCB2F:
QGuiApplicationPrivate::~QGuiApplicationPrivate() (qguiapplication.cpp:1594)
==1742==    by 0x50A7B4C: QApplicationPrivate::~QApplicationPrivate()
==1742==    by 0x5D2830A: cleanup (qscopedpointer.h:60)
==1742==    by 0x5D2830A: ~QScopedPointer (qscopedpointer.h:107)
==1742==    by 0x5D2830A: QObject::~QObject() (qobject.cpp:884)
==1742==    by 0x5CFB32D: QCoreApplication::~QCoreApplication()
==1742==    by 0x56BEE7C: QGuiApplication::~QGuiApplication()
==1742==    by 0x50A9CA3: QApplication::~QApplication()
==1742==    by 0x4011A8: main (Main.cpp:22)

...but also, I think I found the bug:

  int main(int argc, char** argv)
    // ...some init code...

    QApplication app{argc, argv};

    auto* window = new my::Window;

    return app.exec();

(I didn't write that!)

I suspect the window outliving the QApplication instance (and also,
never being reaped properly) is the problem. After changing the above
code to stack-allocate the Window, no more crash.

Should I still report this?


More information about the Interest mailing list