Describe the bug
Gymnasium 1.0.0 added the width and height parameters to the initialization method of the MujocoRenderer class. If no values are passed in, they default to None and this causes rendering to fail when the render_mode is set to rgb_array (at least for on-screen mode - I did not try rendering off-screen).
Exception ignored in: <function GLContext.__del__ at 0x7f63e7e00c10>
Traceback (most recent call last):
File "/home/violasox/venv/lib/python3.8/site-packages/mujoco/glfw/__init__.py", line 41, in __del__
self.free()
File "/home/violasox/venv/lib/python3.8/site-packages/mujoco/glfw/__init__.py", line 34, in free
if self._context:
AttributeError: 'GLContext' object has no attribute '_context'
Traceback (most recent call last):
File "sample.py", line 10, in <module>
main()
File "sample.py", line 7, in main
img_arr = env.render()
File "/home/violasox/venv/lib/python3.8/site-packages/gymnasium/core.py", line 332, in render
return self.env.render()
File "/home/violasox/venv/lib/python3.8/site-packages/gymnasium/wrappers/common.py", line 409, in render
return super().render()
File "/home/violasox/venv/lib/python3.8/site-packages/gymnasium/core.py", line 332, in render
return self.env.render()
File "/home/violasox/venv/lib/python3.8/site-packages/gymnasium/wrappers/common.py", line 301, in render
return env_render_passive_checker(self.env)
File "/home/violasox/venv/lib/python3.8/site-packages/gymnasium/utils/passive_env_checker.py", line 361, in env_render_passive_checker
result = env.render()
File "/home/kc/Research/empowerment/Gymnasium-Robotics-RenderFix/gymnasium_robotics/envs/robot_env.py", line 313, in render
return self.mujoco_renderer.render(self.render_mode)
File "/home/violasox/venv/lib/python3.8/site-packages/gymnasium/envs/mujoco/mujoco_rendering.py", line 706, in render
viewer = self._get_viewer(render_mode=render_mode)
File "/home/violasox/venv/lib/python3.8/site-packages/gymnasium/envs/mujoco/mujoco_rendering.py", line 730, in _get_viewer
self.viewer = OffScreenViewer(
File "/home/violasox/venv/lib/python3.8/site-packages/gymnasium/envs/mujoco/mujoco_rendering.py", line 155, in __init__
super().__init__(model, data, width, height, max_geom, visual_options)
File "/home/violasox/venv/lib/python3.8/site-packages/gymnasium/envs/mujoco/mujoco_rendering.py", line 53, in __init__
self.viewport = mujoco.MjrRect(0, 0, width, height)
TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
1. mujoco._render.MjrRect(left: int, bottom: int, width: int, height: int)
Invoked with: 0, 0, None, None
System Info
Clone the latest Gymnasium-Robotics commit (f756676), create a new python venv virtual environment and run pip install -e .
Ubuntu 20.04
Python 3.8
Additional context
I was able to fix this issue by passing the height and width parameters in the BaseRobotEnv class to the MujocoRenderer in robot_env.py. I will submit a pull request for this fix.
Checklist
[x] I have checked that there is no similar issue in the repo (required)
Describe the bug Gymnasium 1.0.0 added the
width
andheight
parameters to the initialization method of the MujocoRenderer class. If no values are passed in, they default to None and this causes rendering to fail when therender_mode
is set torgb_array
(at least for on-screen mode - I did not try rendering off-screen).Code example
Stack trace:
System Info
pip install -e .
Additional context I was able to fix this issue by passing the height and width parameters in the
BaseRobotEnv
class to theMujocoRenderer
inrobot_env.py
. I will submit a pull request for this fix.Checklist