File tree Expand file tree Collapse file tree
dm_control/_render/pyopengl Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4141
4242# pylint: disable=g-import-not-at-top
4343from dm_control ._render .pyopengl import egl_ext as EGL
44+ from OpenGL import error
4445
4546
4647def 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
6266EGL_DISPLAY = create_initialized_headless_egl_display ()
You can’t perform that action at this time.
0 commit comments