I am currently switching my graphics toolkit over to use VAOs and VBOs instead of the legacy functions. I need a way to ensure that after the user's program runs, and even if it crashes, it will still clean up before execution stops. I also need the traceback to be printed, else the end user will not be able to see what went wrong with their code - or mine.
Here is a general overview of how my toolkit works: The end developer creates a PyQt5 app with a QOpenGLWidget in it. They import the shader and whatever shape classes they need from the shaderProgram file, then instantiate the shader. If they want to add a shape to the scene, they just instantiate a shape object, then call the shader's addShape function with the new shape. This is designed to be as easy as possible to use, but should offer lots of features when it's done.
test.py:
from PyQt5.QtWidgets import QApplication, QMainWindow, QOpenGLWidget
from shaderProgram import shader, cube
import sys
def run():
app = QApplication([])
window = mainWindow()
window.show()
sys.exit(app.exec_())
class mainWindow(QMainWindow):
def __init__(self):
super(mainWindow, self).__init__()
self.setGeometry(0, 0, 500, 500)
self.openGLWidget = QOpenGLWidget(self)
self.shader = shader(self, self.openGLWidget)
self.shader.resize(500, 500)
self.openGLWidget.setGeometry(0, 0, 500, 500)
self.cube1 = cube((0, 0, 0))
self.cube2 = cube((1, 0, 0))
self.cube3 = cube((0, 0, 1))
self.shader.addShapes(self.cube1, self.cube2, self.cube3)
self.shader.navigate(vVal = -45)
self.shader.update()
if __name__ == '__main__':
run()
block diagram of shaderProgram.py:
import stuff
class shader():
def __init__():
def addShapes():
def update():
def resize():
def navigate():
def initGL():
def paintGL():
class shape():
class shape():
#...
GitHub repo: https://github.com/AwesomeCronk/pyGPU - note: I have not yet begun implementing the buffers because I do not want to test it without first making a safety/cleanup system, but this GitHub repo has the entire source as of now and shows the structure of the workflow.
Without modifying the way the end developer writes their code, how can I make sure the VAOs, VBOs, and custom shaders are cleaned up and deleted if there is a crash?