Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-36746

Regression: Crash on exit when more than one QGLWidget is shown (Mac OS)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P1: Critical P1: Critical
    • 5.3.0 Beta1
    • 5.2.1
    • GUI: OpenGL
    • None
    • Mac OS 10.9.1 Mavericks; MacBook Pro; Qt5.2.1; llvm-g++-4.2
    • macOS
    • 72ba4cd3858773757d3cc5a66f7859a483b6475b

      On Qt5.2.1, I can't find a way to show two or more QGLWidgets in the same window without triggering a crash when they are deallocated. In my testing, the widgets operate properly while they are live, but they cause a crash when they are deallocated manually or when the program exits.

      The attached test program provides the minimum necessary conditions for the crash:

      #include <QApplication>
      #include <QWidget>
      #include <QHBoxLayout>
      #include <QGLWidget>
      
      int main(int argc, char *argv[])
      {
        QApplication a(argc, argv);
      
        QWidget *topLevel = new QWidget;
        topLevel->setLayout(new QHBoxLayout);
      
        QGLWidget *firstGLWidget = new QGLWidget;
        topLevel->layout()->addWidget(firstGLWidget);
      
        QGLWidget *secondGLWidget = new QGLWidget;
        topLevel->layout()->addWidget(secondGLWidget);
      
        topLevel->resize(320,200);
        topLevel->show();
      
      //  delete secondGLWidget; // OK
      //  delete firstGLWidget;  // CRASH
      //  delete topLevel;       // CRASH
      
        return a.exec();
      } // CRASH on exit
      

      On my machine, this crashes about half of the time (it exits normally otherwise).

      I have tried manually deleting the various widgets, and it appears that deleting firstGLWidget can be safely done and prevents the crash on exit. But deleting secondGLWidget or topLevel will crash. And if I instantiate three QGLWidgets, then I haven't found a combination of steps that would prevent a crash.

      Removing the widgets from the layout using
      topLevel->layout()->removeWidget(xxGLWidget);
      can prevent the crash, but then I'd need to keep them around because any attempt to delete them fails.

      The stack trace on exit for the above program shows that it's deallocating one of the widgets; however, the location of the crash is not consistent:

        malloc: *** error for object 0x10163c740: pointer being freed was not allocated
      
          Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
        0   libsystem_kernel.dylib        	0x00007fff895d7866 __pthread_kill + 10
        1   libsystem_pthread.dylib       	0x00007fff89d7235c pthread_kill + 92
        2   libsystem_c.dylib             	0x00007fff8964cbba abort + 125
        3   libsystem_malloc.dylib        	0x00007fff93211093 free + 411
        4   QtCore                        	0x0000000100d95f45 QObject::~QObject() + 181
        5   QtGui                         	0x00000001006f502c QWindow::~QWindow() + 140
        6   QtWidgets                     	0x00000001000f71fb QWidgetWindow::~QWidgetWindow() + 139
        7   QtWidgets                     	0x00000001000f711e QWidgetWindow::~QWidgetWindow() + 14
        8   QtWidgets                     	0x00000001000f49d3 QWidgetPrivate::deleteTLSysExtra() + 83
        9   QtWidgets                     	0x00000001000f4828 QWidget::destroy(bool, bool) + 888
        10  QtWidgets                     	0x00000001000f47da QWidget::destroy(bool, bool) + 810
        11  QtWidgets                     	0x000000010009e15e QApplication::~QApplication() + 270
        12  com.yourcompany.glwidgettest  	0x0000000100003a92 main + 562 (main.cpp:27)
        13  com.yourcompany.glwidgettest  	0x0000000100003854 start + 52
      

      All of this worked fine on 5.2.0, and this test program also succeeds there. This also works fine on Qt5.2.1/Ubuntu.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            sorvig Morten Sørvig
            wro William Overall
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes