3

I am moving from Winpython3.4.3.7Qt4 to Winpython3.x.x.xQt5 (I tried a bunch of versions), and I am having the following problem:

The following minimal code (it does nothing usable, but demonstrates the error):

from PyQt5 import QtWidgets
import OpenGL.GL as gl
from PyQt5.QtOpenGL import QGLWidget
qapp = QtWidgets.QApplication([])
window = QGLWidget()
window.makeCurrent()
index = gl.glGenLists(1)
print(index)

runs on all my machines with Winpython3.4.3.7Qt4 and prints '1'. When I use Winpython3.x.x.xQt5, it does not run on my virtual machines anymore. The error I get is:

Traceback (most recent call last):
  File ".\opengl.py", line 12, in <module>
    index = gl.glGenLists(1)
  File "C:\Winpython-64bit-3.6.7.0\python-3.6.7\lib\site-packages\OpenGL\platform\baseplatform.py", line 405, in __call__
    return self( *args, **named )
  File "C:\Winpython-64bit-3.6.7.0\python-3.6.7\lib\site-packages\OpenGL\error.py", line 232, in glCheckError
    baseOperation = baseOperation,
OpenGL.error.GLError: GLError(
        err = 1282,
        description = b'invalid operation',
        baseOperation = glGenLists,
        cArguments = (1,),
        result = 0
)

I have the feeling that window.makeCurrent() isn't coming through, but I have no idea why. What changed in that regard from Qt4 to Qt5?

zeus300
  • 1,017
  • 2
  • 12
  • 30
  • I have tested in Linux with Python 3.7 and PyQt 5.11.2 I have not had any problems – eyllanesc Nov 06 '18 at 16:31
  • Try it on Windows, it may well be that it is only a problem there. And out of four Windows machines, I have one where the code runs without problems. – zeus300 Nov 07 '18 at 06:44
  • 1
    check the OpenGL context version you got. `glGenLists` has been removed from modern versions of OpenGL a decade ago. – derhass Nov 10 '18 at 00:48
  • I modified my answer to include a call to makeCurrent() like in your example, seems the problem is fixed, let me know how it goes for you ;-) – Isma Nov 15 '18 at 09:36

1 Answers1

1

According the OpenGL documentation glGenLists will return GL_INVALID_OPERATION in the following case:

GL_INVALID_OPERATION is generated if glGenLists is executed between the execution of glBegin and the corresponding execution of glEnd.

So it seems you are calling glGenLists before OpenGL has been initialized or between a glBegin glEnd drawing call.

I was able tol solve the issue by creating a widget that inherits from QGLWidget and waiting until it has been initialized before calling gl.glGenLists(1), as you can see below a signal is sent inside the init method:

import sys
import OpenGL.GL as gl

from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import pyqtSignal

from PyQt5.QtOpenGL import QGLWidget


class MyQGLWidget(QGLWidget):
    init = pyqtSignal()

    def __init__(self, parent=None):
        super().__init__(parent)

    def glInit(self):
        super().glInit()
        self.init.emit()

    def gl_gen_lists(self, size):
        return gl.glGenLists(size)


class App(QApplication):
    def __init__(self, sys_argv):
        super().__init__(sys_argv)
        self.qgl_widget = MyQGLWidget()
        self.qgl_widget.init.connect(self.on_init)
        self.qgl_widget.show()

    def on_init(self):
        self.qgl_widget.makeCurrent()
        print(self.qgl_widget.gl_gen_lists(1))


if __name__ == '__main__':
    app = App(sys.argv)
    sys.exit(app.exec_())

And the error is gone...

Reference: http://docs.gl/gl3/glGenLists

Isma
  • 14,604
  • 5
  • 37
  • 51
  • Sorry, Isma, but I get the same error on line 22 of your code. – zeus300 Nov 15 '18 at 10:39
  • Are you using a virtual machine? – Isma Nov 15 '18 at 10:48
  • As a matter of fact, yes, I am. Several, actually. Good hint, because now that I come to think of it, the code works only on the one real machine, and on none of the virtual ones. I just ran my original little sample code above on another real machine, and it works fine. So what changed in the latest QtOpenGL (or wherever the problem is) seems to have to do with virtual machines. That mitigates my problem somewhat, but eventually I would like to use the code on virtual machines, too. (And yes, I know, eventually I will have to convert the code to modern OpenGL.) – zeus300 Nov 15 '18 at 11:50
  • What kind of virtual machine are you using. This is the key, as some of them don't support OpenGL or only a subset of features. – Isma Nov 15 '18 at 11:58
  • It is a KVM based Windows 10. But I think it must be the new Python/Qt/whatever libs rather than the machine, because my pre-Qt5/OpenGL software runs on all the virtual machines I have. – zeus300 Nov 15 '18 at 12:25
  • Maybe you can try GPU passthrough: https://arrayfire.com/using-gpus-kvm-virutal-machines/ although I would first try with a different hypervisor or you can simply move to a previous version of Qt that supports the version of OpenGL supported by KVM – Isma Nov 15 '18 at 12:59