Genesis icon indicating copy to clipboard operation
Genesis copied to clipboard

[Bug]: scene.build() fails with an unactionable PyOpenGL AttributeError when no GL platform is installed (ROCm containers)

Open himanshu748 opened this issue 4 months ago • 1 comments

Bug Description

On a container with no OpenGL libraries installed, scene.build() fails with a PyOpenGL AttributeError that gives no indication of the actual cause. The underlying problem is simply that no GL platform is present, but nothing in the traceback says so, and the scene being built has show_viewer=False and no cameras, so there is no obvious reason for the user to suspect rendering at all.

This is easy to hit on ROCm images specifically. A compute-only ROCm container has no reason to ship libEGL, so the official AMD Radeon Cloud PyTorch/ROCm template does not have one. Any state-based RL workload on such an image dies at scene.build() with the message below.

To be explicit about scope: I am not asking for an option to disable the visualizer. I saw that #1877 asked for that and was closed with a clear "this is not going to happen", and I am not relitigating it. This is only about the error being unactionable. In that same thread a maintainer noted "we are not aware of any machine still facing issues with that at the moment", so this report is mainly to supply one such machine, plus the one-line fix for it.

Steps to Reproduce

On any image without libEGL or libOSMesa (for example rocm/pytorch):

import genesis as gs

gs.init(backend=gs.amdgpu)
scene = gs.Scene(show_viewer=False)   # no viewer
scene.add_entity(gs.morphs.Plane())   # no cameras
scene.build(n_envs=1)
File "genesis/vis/rasterizer.py", line 40, in build
    self._renderer = pyrender.OffscreenRenderer(
File "genesis/ext/pyrender/offscreen.py", line 250, in _create
    from .platforms import egl
File "genesis/ext/pyrender/platforms/egl.py", line 30, in <module>
    from OpenGL import EGL as egl
File "OpenGL/raw/EGL/_types.py", line 87, in <module>
    raw_eglQueryString = _p.PLATFORM.EGL.eglQueryString
AttributeError: 'NoneType' object has no attribute 'eglQueryString'

_p.PLATFORM.EGL is None because PyOpenGL could not load an EGL implementation. The AttributeError is a downstream symptom.

Expected Behavior

An error naming the real cause, for example:

No OpenGL platform available. Genesis builds an offscreen renderer during
scene.build() even when show_viewer=False and no cameras are added.
Install one of:
  apt-get install -y libegl1 libegl-mesa0 libgl1-mesa-dri
  apt-get install -y libosmesa6   # then set PYOPENGL_PLATFORM=osmesa

Workaround

Installing the libraries fixes it, even though nothing is ever drawn:

apt-get install -y libegl1 libegl-mesa0 libgl1-mesa-dri libosmesa6

After that, headless training on gs.amdgpu works well. For reference, on this box a Go2 quadruped runs 4096 parallel environments at about 954k environment-steps per second for physics alone.

Environment

  • Genesis 1.3.0 (PyPI wheel)
  • Backend gs.amdgpu, AMD Radeon PRO gfx1100 (RDNA 3), 48 GB
  • ROCm 7.2.4, torch 2.10.0+rocm7.2.4
  • Ubuntu 22.04 container, Python 3.10.12

Note

Rasterizer.build() already returns early when self._context is None, but Visualizer.__init__ always assigns self._context = RasterizerContext(...), so that branch is unreachable in normal use. Wrapping the pyrender.OffscreenRenderer(...) construction and re-raising with the cause would be enough, and would not change any behaviour for users who do have a GL platform.

Happy to open a PR for the improved message if you would like one.

himanshu748 avatar Jul 29 '26 18:07 himanshu748

This is expected. OpenGL support is not optional, even if no graphical window is created. We do not want to optionally support recording videos, adding camera sensors...etc So we detect early if it is supported, and if not, it raises an exception.

duburcqa avatar Jul 30 '26 13:07 duburcqa