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

QOpenGLWidget crashes when deleting QOpenGLTexture after switching GL Context

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.10.0
    • GUI: OpenGL
    • None
    • OSX 10.11.6

      Python 2.7.10

      PyQt 5.9.2

      Qt 5.10
    • macOS

    Description

      When a QOpenGLWidget is inside a QDockWidget, and you undock the widget, then try deleting an old QOpenGLTexture from the last context, there is a segfault.

      Here is a minimal PyQt example. Undock and redock the widget. The code will crash between the two checkpoints:

       

      from OpenGL import GL
      from PyQt5 import QtWidgets, QtCore, QtGui
      
      class Test(QtWidgets.QMainWindow):
          def __init__(self):
              super(Test, self).__init__()
      
              self.dock = QtWidgets.QDockWidget("dock", self)
              self.ogl = GLWidget()
      
              self.dock.setWidget(self.ogl)
              self.dock.setFloating(False)
              self.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.dock)
      
      class GLWidget(QtWidgets.QOpenGLWidget):
          def __init__(self):
              QtWidgets.QOpenGLWidget.__init__(self)
              self.setMinimumSize(640, 480)
      
              # Set to any image
              self.qim = QtGui.QImage("images/gridDark.jpg")
      
          def paintGL(self):
              GL.glLoadIdentity()
              GL.glTranslatef(0, 0, -1)
              GL.glColor3f( 1.0, 1.5, 0.0 );
      
              print "About to set texture (checkpoint 0)"
              self.texture = QtGui.QOpenGLTexture(self.qim)
              print "Texture has been set (checkpoint 1)"
              self.texture.bind()
      
              w, h = 10,10
              GL.glEnable(GL.GL_TEXTURE_2D)
              GL.glColor3f( 1.0, 1.0, 1.0 )
              GL.glLoadIdentity()
              GL.glBindTexture(GL.GL_TEXTURE_2D, self.texture.textureId())
              GL.glBegin(GL.GL_QUADS)
              GL.glTexCoord2d(0,0)
              GL.glVertex2d(0,0)
              GL.glTexCoord2d(1,0)
              GL.glVertex2d(w,0)
              GL.glTexCoord2d(1,1)
              GL.glVertex2d(w,h)
              GL.glTexCoord2d(0,1)
              GL.glVertex2d(0,h)
              GL.glEnd()
      
              GL.glFlush()
      
          def initializeGL(self):
              GL.glMatrixMode(GL.GL_PROJECTION)
              GL.glOrtho(0, 1, 1, 0, -1.0, 100.0)
              GL.glMatrixMode(GL.GL_MODELVIEW)
      
      if __name__ == '__main__':
          QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_ShareOpenGLContexts)
          app = QtWidgets.QApplication([])
          window = Test()
          window.show()
          app.exec_() 

      Here is a truncated stacktrace (from lldb):

      • thread #1: tid = 0x5655, 0x000000010287a323 QtGui`QOpenGLContext::areSharing(QOpenGLContext*, QOpenGLContext*) + 19, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
        * frame #0: 0x000000010287a323 QtGui`QOpenGLContext::areSharing(QOpenGLContext*, QOpenGLContext*) + 19
        frame #1: 0x0000000102b3cd95 QtGui`___lldb_unnamed_symbol3149$$QtGui + 53
        frame #2: 0x0000000102b42e02 QtGui`QOpenGLTexture::~QOpenGLTexture() + 34
        frame #3: 0x000000010258a96a QtGui.so`dealloc_QOpenGLTexture(_sipSimpleWrapper*) + 58
        frame #4: 0x00000001024c253f sip.so`forgetObject + 174
        frame #5: 0x00000001024c0a1f sip.so`sipSimpleWrapper_dealloc + 14
        frame #6: 0x00000001006afce5 Python`subtype_dealloc + 667
        frame #7: 0x000000010068f82b Python`dict_dealloc + 129
        frame #8: 0x000000010066da04 Python`instance_dealloc + 387
        frame #9: 0x0000000100686051 Python`list_dealloc + 123
        frame #10: 0x0000000100690aa1 Python`insertdict_by_entry + 249
        frame #11: 0x000000010068f3a3 Python`insertdict + 51
        frame #12: 0x000000010068ea61 Python`dict_set_item_by_hash_or_entry + 40
        frame #13: 0x0000000100695001 Python`_PyObject_GenericSetAttrWithDict + 325
        

        The issue can be fixed by changing `self.texture` to just `texture`.

       

      Attachments

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

        Activity

          People

            qt.team.graphics.and.multimedia Qt Graphics Team
            artoonie Armin Samii
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes