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

A QWindow that is closed with [x] button cannot be madeCurrent again.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.2.1
    • 5.2.0
    • GUI: OpenGL
    • None
    • Mac OS X
    • ec03058fa5b84b4570a2158bf2179f7ba4d83b99

    Description

      Run the following application and close one of the windows using the red [x] button. When it shows up again as the timer fires, it will be rendered in white because makeCurrent() failed.

      The root cause is that QCocoaGLContext::makeCurrent() "optimizes" away makeCurrent calls when the surface is unchanged. However in the case of a closed window, we need to make current again. I suspect a fix is simply to unset the "old" surface as the window is closed.

      #include <QtGui>
      
      class Window : public QWindow
      {
      public:
          Window()
              : gl(0)
          {
              setSurfaceType(OpenGLSurface);
              startTimer(5000);
          }
      
          void timerEvent(QTimerEvent *) {
              if (!isVisible())
                  show();
          }
      
          void exposeEvent(QExposeEvent *) {
              if (!isExposed())
                  return;
      
              if (!gl) {
                  gl = new QOpenGLContext();
                  gl->create();
              }
      
              bool current = gl->makeCurrent(this);
              if (current) {
                  float r = (rand() & 1000) / 1000.;
                  float g = (rand() & 1000) / 1000.;
                  float b = (rand() & 1000) / 1000.;
                  glClearColor(r, g, b, 1);
                  glClear(GL_COLOR_BUFFER_BIT);
                  gl->swapBuffers(this);
              } else {
                  qDebug() << "makeCurrent failed, not drawing anything...";
              }
          }
      
          QOpenGLContext *gl;
      };
      
      int main(int argc, char *argv[])
      {
          QGuiApplication a(argc, argv);
      
          Window w1;
          w1.setGeometry(100, 100, 100, 100);
          w1.show();
      
          Window w2;
          w2.setGeometry(200, 200, 100, 100);
          w2.show();
      
          return a.exec();
      }
      

      Attachments

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

        Activity

          People

            sletta Gunnar Sletta
            sletta Gunnar Sletta
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes