Describe the bug
When I run env.render(mode="human") everything works as it should. However, if instead I run env.render(mode="rgb_array") I get the error "ERROR: GLEW initalization error: Missing GL version". I am aware of the issue here, and I have added export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libGLEW.so (actually before doing this, I don't think mode="human" worked either), however it doesn't help fix this. It seems that someone else was having this issue, but it doesn't seem to have been reposted here as suggested.
Strangely, if I first call env.render(mode="human") I am able to call env.render(mode="rgb_array") afterwards without getting this error. So, for example, the following code works:
`from gym.envs.mujoco.half_cheetah_v3 import HalfCheetahEnv
import numpy as np
env = HalfCheetahEnv()
test = env.reset()
env.render(mode="human")
for i in range(10000):
a,b,c,d = env.step(np.random.randn(6).clip(-1,1))
img=env.render(mode="rgb_array")`
But if I miss out the initial env.render(mode="human") I get the error.
Desktop (please complete the following information):
Environment
echo $LD_LIBRARY_PATH - /home/henry/.mujoco/mujoco200/binecho $HOME /home/henryecho $USER - henryAs someone described in a thread for gym. If you render once as 'human' it works afterwards. After trying that, I figured a workaround:
Add this line at the beginning of your script:
from mujoco_py import GlfwContext
GlfwContext(offscreen=True) # Create a window to init GLFW.
That solves the issue for me.
Using mujoco_py==1.50.1.1, I had the same problem, but in this version, GlfwContext was not being exported. Simply exporting it and following the workaround proposed by @jendelel solved the issue.
I am having the exact same problem, but I am using a windows machine.
Do you have an idea how to solve it on windows?
@zoharri you can use the same method @jendelel and @khedd mentioned to fix the issue on Windows.
mujoco_py.MjRenderContextOffscreen(self.sim, -1)
In mujoco_env.py change -1 to be 0 works for me
Most helpful comment
As someone described in a thread for gym. If you render once as 'human' it works afterwards. After trying that, I figured a workaround:
Add this line at the beginning of your script:
That solves the issue for me.