Crash after calling initializeOpenGLFunctions
-
I'm trying to follow along with some of the official tutorials using OpenGL (specifically this one), and I am running in to an issue doing basic function initialization. I created this basic script to showcase my issue.
from PySide6.QtOpenGLWidgets import QOpenGLWidget from PySide6.QtGui import QOpenGLFunctions from PySide6.QtWidgets import QApplication import sys class Test(QOpenGLWidget, QOpenGLFunctions): def __init__(self): super().__init__() def initializeGL(self) -> None: self.makeCurrent() print('Initializing') self.initializeOpenGLFunctions() if __name__ == '__main__': app = QApplication() win = Test() win.show() sys.exit(app.exec())
The issue comes when the inherited QOpenGLWidget.initializeGL method is called, inside of which I call the inherited QOpenGLFunctions.initializeOpenGLFunctions method to... initialize the OpenGL Functions. This just leads to a hard application crash - no errors, no stacktrace. I have tried this using the QtGui.QOpenGLFunctions implementation and the QtGui.QOpenGLFunctions_version implementations, and all of them lead to this issue.
I have an AMD Rx 5700xt using the latest drivers, and use Python 3.9.1, PySide6 version 6.1.2.
Am I doing something wrong here? Can anyone else replicate this issue (perhaps on NVIDIA hardware)?
-
I'm trying to follow along with some of the official tutorials using OpenGL (specifically this one), and I am running in to an issue doing basic function initialization. I created this basic script to showcase my issue.
from PySide6.QtOpenGLWidgets import QOpenGLWidget from PySide6.QtGui import QOpenGLFunctions from PySide6.QtWidgets import QApplication import sys class Test(QOpenGLWidget, QOpenGLFunctions): def __init__(self): super().__init__() def initializeGL(self) -> None: self.makeCurrent() print('Initializing') self.initializeOpenGLFunctions() if __name__ == '__main__': app = QApplication() win = Test() win.show() sys.exit(app.exec())
The issue comes when the inherited QOpenGLWidget.initializeGL method is called, inside of which I call the inherited QOpenGLFunctions.initializeOpenGLFunctions method to... initialize the OpenGL Functions. This just leads to a hard application crash - no errors, no stacktrace. I have tried this using the QtGui.QOpenGLFunctions implementation and the QtGui.QOpenGLFunctions_version implementations, and all of them lead to this issue.
I have an AMD Rx 5700xt using the latest drivers, and use Python 3.9.1, PySide6 version 6.1.2.
Am I doing something wrong here? Can anyone else replicate this issue (perhaps on NVIDIA hardware)?
@nmthastings PySide accepts the double inherence in few cases so if possible it is better to use the composition.
import sys from PySide6.QtGui import QOpenGLFunctions from PySide6.QtWidgets import QApplication from PySide6.QtOpenGLWidgets import QOpenGLWidget class Test(QOpenGLWidget): def __init__(self): super().__init__() self.opengl_functions = QOpenGLFunctions() def initializeGL(self) -> None: self.makeCurrent() print("Initializing") self.opengl_functions.initializeOpenGLFunctions() if __name__ == "__main__": app = QApplication() win = Test() win.show() sys.exit(app.exec())
-
@eyllanesc Thanks for the tip. That does work to solve the issue. I find it odd that the official PySide documentation showcases the double inheritance case, but it doesn't seem to work. Is this just a case of the docs being out of date?
-
@eyllanesc Thanks for the tip. That does work to solve the issue. I find it odd that the official PySide documentation showcases the double inheritance case, but it doesn't seem to work. Is this just a case of the docs being out of date?
@nmthastings Those examples are really a bad translation from C++ to Python, for example
QOpenGLFunctions_3_2_Core f = QOpenGLContext.currentContext().versionFunctions<QOpenGLFunctions_3_2_Core>()
is clearly not a valid python code. Another example is that the first code usesprotected:
, which clearly does not exist in python. In C++ you can declare float by placing "f" at the end(f.glClearColor(1.0f, 1.0f, 1.0f, 1.0f)
) since by default the numbers with decimals will be double but in python there is no equivalence.It seems that they have not given affection to the documentation so it would be that you report it as a bug