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

Creating QGLFrameBuffers in multiple QGLWidget threads cause crash on Mac

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • Icon: P2: Important P2: Important
    • None
    • 4.8.5
    • GUI: OpenGL
    • Mac OS X 10.7
    • macOS

      Application below crashes on Mac (10.7). Works on Windows (7).

      Application works when creating QFrameBufferObject also in gui thread. See comment line from main.cpp.

      Doesn't work on Qt 5.1.1 at all. Displays error:"Cannot make QOpenGLContext current in a different thread".

      main.cpp
      #include <QApplication>
      #include <QFutureWatcher>
      #include <QFutureSynchronizer>
      #include <QtConcurrentRun>
      #include <QThread>
      #include <QGLWidget>
      #include <QGLFramebufferObject>
      
      void threadTask(QGLWidget *glWidget, int i)
      {
        qDebug() << "task:" << i << " thread: " << QThread::currentThreadId();
        glWidget->makeCurrent();
        QGLFramebufferObject * frameBufferObject = new QGLFramebufferObject(QSize(128, 128));
        glWidget->doneCurrent();
      }
      
      int main(int argc, char ** argv)
      {
        QApplication app(argc, argv);
        qDebug() << "ideal thread count" << QThread::idealThreadCount();
        QGLWidget * glWidget = new QGLWidget();
        QFutureSynchronizer<void> * futures = new QFutureSynchronizer<void>();
          for(int i=0; i<20; i++) {
            QGLWidget * threadWidget = new QGLWidget(glWidget);
            threadWidget->makeCurrent();
            // !!! NEED TO CREATE FBO HERE OR IT CRASH! !!!
            //QGLFramebufferObject * frameBufferObject = new QGLFramebufferObject(QSize(128, 128));
            threadWidget->doneCurrent();
            futures->addFuture(QtConcurrent::run(threadTask, threadWidget, i));
        }
        futures->waitForFinished();
        glWidget->show();
        return( app.exec() );
      }
      
      project.pro
      TEMPLATE = app
      QT = core gui opengl
      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets concurrent
      CONFIG -= app_bundle
      SOURCES += main.cpp
      

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

            sletta Gunnar Sletta
            qtcomsupport Qt Support
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes