Skip to content

Commit 0260f3e

Browse files
saran-talimuldal
authored andcommitted
Catch and ignore GLError in the PyOpenGL implementation of create_initialized_headless_egl_display.
Fixes #70 PiperOrigin-RevId: 240153693
1 parent 978230f commit 0260f3e

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

dm_control/_render/pyopengl/egl_renderer.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,26 @@
4141

4242
# pylint: disable=g-import-not-at-top
4343
from dm_control._render.pyopengl import egl_ext as EGL
44+
from OpenGL import error
4445

4546

4647
def create_initialized_headless_egl_display():
4748
"""Creates an initialized EGL display directly on a device."""
48-
display = EGL.EGL_NO_DISPLAY
49-
devices = EGL.eglQueryDevicesEXT()
50-
for device in devices:
49+
for device in EGL.eglQueryDevicesEXT():
5150
display = EGL.eglGetPlatformDisplayEXT(
5251
EGL.EGL_PLATFORM_DEVICE_EXT, device, None)
53-
if display and EGL.eglGetError() == EGL.EGL_SUCCESS:
54-
initialized = EGL.eglInitialize(display, None, None)
55-
if EGL.eglGetError() == EGL.EGL_SUCCESS and initialized == EGL.EGL_TRUE:
56-
break
52+
if display != EGL.EGL_NO_DISPLAY and EGL.eglGetError() == EGL.EGL_SUCCESS:
53+
# `eglInitialize` may or may not raise an exception on failure depending
54+
# on how PyOpenGL is configured. We therefore catch a `GLError` and also
55+
# manually check the output of `eglGetError()` here.
56+
try:
57+
initialized = EGL.eglInitialize(display, None, None)
58+
except error.GLError:
59+
pass
5760
else:
58-
display = EGL.EGL_NO_DISPLAY
59-
return display
61+
if initialized == EGL.EGL_TRUE and EGL.eglGetError() == EGL.EGL_SUCCESS:
62+
return display
63+
return EGL.EGL_NO_DISPLAY
6064

6165

6266
EGL_DISPLAY = create_initialized_headless_egl_display()

0 commit comments

Comments
 (0)