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

QCocoaWindow::setVisible accesses destroyed QCocoaGLContext via m_glContext member variable

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P1: Critical
    • None
    • 5.2.1
    • GUI: OpenGL
    • None
    • Mac OS X 10.8.5
    • 72ba4cd3858773757d3cc5a66f7859a483b6475b

    Description

      With Qt 5.2.1, our application started getting random crashes, usually after closing a dialog that had a QGLWidget in it.

      I found QTBUG-35600 and discovered that the sample application provided also crashes or reports one of the following errors:
      "QObject: shared QObject was deleted directly. The program is malformed and may crash."
      or
      "malloc: *** error for object 0x1114e56c0: pointer being freed was not allocated"

      After looking through the code, and at changes in 5.2, I found the changes for QTBUG-35363. Removing the changes resolved the issue. So then I tried to figure out why that was the case.

      When a QGLWidget is deleted, it first deletes the openGL context, then the QWidget destructor is called and eventually calls QCocoaWindow::setVisible(false). At this point, m_glContext has been deleted but not cleared, so the call "m_glContext->windowWasHidden()" corrupts memory, leading to later random crashes.

      A solution that is working for me is to call doneCurrent() on the context in the QGLWidget destructor:

      QGLWidget::~QGLWidget()
      {
          Q_D(QGLWidget);
          if (d->glcx) // ADDED BLOCK. This clears the member m_glContext in QCocoaWindow before we delete it below.
          {
              d->glcx->doneCurrent();
          }
          delete d->glcx;
          d->glcx = 0;
          d->cleanupColormaps();
      }
      

      Attachments

        For Gerrit Dashboard: QTBUG-36820
        # Subject Branch Project Status CR V

        Activity

          People

            sorvig Morten Sørvig
            dzedsystems Dyami Caliri
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes