Skip to content

Commit 5d5a087

Browse files
authored
Merge pull request #226 from compas-dev/clear_errors
clear lingering errors before initializing OpenGL
2 parents 0a63b2d + dd24196 commit 5d5a087

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Changed
1313

14+
* Fixed `invalid enumerant` error (1280) on call to `Viewer.show()` which occurs due to lingering OpenGL errors.
15+
1416
### Removed
1517

1618

src/compas_viewer/renderer/renderer.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,13 @@ def clear(self):
205205
"""
206206
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) # type: ignore
207207

208+
def _clear_opengl_errors(self):
209+
while True:
210+
error = GL.glGetError()
211+
if error == GL.GL_NO_ERROR:
212+
break
213+
print(f"Cleared stale OpenGL error: {error}")
214+
208215
def initializeGL(self):
209216
"""
210217
Initialize the OpenGL canvas.
@@ -220,6 +227,9 @@ def initializeGL(self):
220227
* https://doc.qt.io/qtforpython-6/PySide6/QtOpenGL/QOpenGLWindow.html#PySide6.QtOpenGL.PySide6.QtOpenGL.QOpenGLWindow.initializeGL
221228
222229
"""
230+
# any stale errors caused e.g. by the windowing framework and were not cleared may trigger a crash as soon as we start issuing GL calls.
231+
self._clear_opengl_errors()
232+
223233
GL.glClearColor(*self.viewer.config.renderer.backgroundcolor.rgba)
224234
GL.glPolygonOffset(1.0, 1.0)
225235
GL.glEnable(GL.GL_CULL_FACE)

0 commit comments

Comments
 (0)