Skip to content

Commit 68bbc63

Browse files
committed
Copilot lied and made up things twice about this...
aboutToBeDestroyed exists, but it is an attribute of the context, not the widget. And it must be connected after initializeGL (where the context comes into existence), not earlier. The signal is used for re-parenting, so normal exit does not fire the signal.
1 parent 9406189 commit 68bbc63

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

openglwidget_abouttobedestroyed.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66
class MyOpenGLWidget(QOpenGLWidget):
77
def __init__(self, parent=None):
88
super().__init__(parent)
9-
# Connect the aboutToBeDestroyed signal to your cleanup slot
10-
#self.aboutToBeDestroyed.connect(self.cleanupGL)
119

12-
#@pyqtSlot()
13-
#def cleanupGL(self):
14-
# # This will be called just before the GL context is destroyed
15-
# print("OpenGL context is about to be destroyed. Clean up GPU resources here.")
10+
@pyqtSlot()
11+
def cleanupGL(self):
12+
# This will be called just before the GL context is destroyed
13+
print("OpenGL context is about to be destroyed. Clean up GPU resources here.")
1614

1715
def closeEvent(self, event):
1816
print("Widget is about to be destroyed")
1917
super().closeEvent(event)
2018

2119
def initializeGL(self):
2220
print("initializeGL: OpenGL context created.")
21+
# Connect the aboutToBeDestroyed signal to your cleanup slot
22+
self.context().aboutToBeDestroyed.connect(self.cleanupGL)
2323

2424
def resizeGL(self, w, h):
2525
print(f"resizeGL: {w}x{h}")

0 commit comments

Comments
 (0)