Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to initialize OpenGL #187

Open
richardrl opened this issue Jan 29, 2018 · 25 comments
Open

Failed to initialize OpenGL #187

richardrl opened this issue Jan 29, 2018 · 25 comments

Comments

@richardrl
Copy link

richardrl commented Jan 29, 2018

I want to use raw image observations, so I am trying to call the _read_pixels_as_in_window(self) in mjviewer.py. However, getting this error:

LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libGLEW.so:/usr/lib/nvidia-384/libGL.so python trpo_run_mujoco.py --env 'Reacher-Pixel-v0'
Logging to /tmp/openai-2018-01-28-23-59-19-815938
2018-01-28 23:59:19.816385: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
Device mapping: no known devices.
2018-01-28 23:59:19.816722: I tensorflow/core/common_runtime/direct_session.cc:297] Device mapping:

[2018-01-28 23:59:19,816] Making new env: Reacher-Pixel-v0
Compiling /home/richard/lib/mujoco-py/mujoco_py/cymj.pyx because it changed.
[1/1] Cythonizing /home/richard/lib/mujoco-py/mujoco_py/cymj.pyx
running build_ext
building 'mujoco_py.cymj' extension
creating /home/richard/lib/mujoco-py/mujoco_py/generated/_pyxbld_LinuxExtensionBuilder
creating /home/richard/lib/mujoco-py/mujoco_py/generated/_pyxbld_LinuxExtensionBuilder/temp.linux-x86_64-3.5
creating /home/richard/lib/mujoco-py/mujoco_py/generated/_pyxbld_LinuxExtensionBuilder/temp.linux-x86_64-3.5/home
creating /home/richard/lib/mujoco-py/mujoco_py/generated/_pyxbld_LinuxExtensionBuilder/temp.linux-x86_64-3.5/home/richard
creating /home/richard/lib/mujoco-py/mujoco_py/generated/_pyxbld_LinuxExtensionBuilder/temp.linux-x86_64-3.5/home/richard/lib
creating /home/richard/lib/mujoco-py/mujoco_py/generated/_pyxbld_LinuxExtensionBuilder/temp.linux-x86_64-3.5/home/richard/lib/mujoco-py
creating /home/richard/lib/mujoco-py/mujoco_py/generated/_pyxbld_LinuxExtensionBuilder/temp.linux-x86_64-3.5/home/richard/lib/mujoco-py/mujoco_py
creating /home/richard/lib/mujoco-py/mujoco_py/generated/_pyxbld_LinuxExtensionBuilder/temp.linux-x86_64-3.5/home/richard/lib/mujoco-py/mujoco_py/gl
gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/home/richard/lib/mujoco-py/mujoco_py -I/home/richard/.mujoco/mjpro150/include -I/home/richard/anaconda3/envs/py35/lib/python3.5/site-packages/numpy/core/include -I/home/richard/lib/mujoco-py/mujoco_py/vendor/egl -I/home/richard/anaconda3/envs/py35/include/python3.5m -c /home/richard/lib/mujoco-py/mujoco_py/cymj.c -o /home/richard/lib/mujoco-py/mujoco_py/generated/_pyxbld_LinuxExtensionBuilder/temp.linux-x86_64-3.5/home/richard/lib/mujoco-py/mujoco_py/cymj.o -fopenmp -w
gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/home/richard/lib/mujoco-py/mujoco_py -I/home/richard/.mujoco/mjpro150/include -I/home/richard/anaconda3/envs/py35/lib/python3.5/site-packages/numpy/core/include -I/home/richard/lib/mujoco-py/mujoco_py/vendor/egl -I/home/richard/anaconda3/envs/py35/include/python3.5m -c /home/richard/lib/mujoco-py/mujoco_py/gl/eglshim.c -o /home/richard/lib/mujoco-py/mujoco_py/generated/_pyxbld_LinuxExtensionBuilder/temp.linux-x86_64-3.5/home/richard/lib/mujoco-py/mujoco_py/gl/eglshim.o -fopenmp -w
creating /home/richard/lib/mujoco-py/mujoco_py/generated/_pyxbld_LinuxExtensionBuilder/lib.linux-x86_64-3.5
creating /home/richard/lib/mujoco-py/mujoco_py/generated/_pyxbld_LinuxExtensionBuilder/lib.linux-x86_64-3.5/mujoco_py
gcc -pthread -shared -L/home/richard/anaconda3/envs/py35/lib -Wl,-rpath=/home/richard/anaconda3/envs/py35/lib,--no-as-needed /home/richard/lib/mujoco-py/mujoco_py/generated/_pyxbld_LinuxExtensionBuilder/temp.linux-x86_64-3.5/home/richard/lib/mujoco-py/mujoco_py/cymj.o /home/richard/lib/mujoco-py/mujoco_py/generated/_pyxbld_LinuxExtensionBuilder/temp.linux-x86_64-3.5/home/richard/lib/mujoco-py/mujoco_py/gl/eglshim.o -L/home/richard/.mujoco/mjpro150/bin -L/home/richard/anaconda3/envs/py35/lib -Wl,--enable-new-dtags,-R/home/richard/.mujoco/mjpro150/bin -lmujoco150 -lglewegl -lpython3.5m -o /home/richard/lib/mujoco-py/mujoco_py/generated/_pyxbld_LinuxExtensionBuilder/lib.linux-x86_64-3.5/mujoco_py/cymj.cpython-35m-x86_64-linux-gnu.so -fopenmp
get_obs
Creating window glfw
Found 1 GPUs for rendering. Using device 0.
Could not make EGL context current
Traceback (most recent call last):
  File "trpo_run_mujoco.py", line 35, in <module>
    main()
  File "trpo_run_mujoco.py", line 31, in main
    train(args.env, num_timesteps=args.num_timesteps, seed=args.seed)
  File "trpo_run_mujoco.py", line 21, in train
    env = make_mujoco_env(env_id, workerseed)
  File "/home/richard/baselines/baselines/common/cmd_util.py", line 34, in make_mujoco_env
    env = gym.make(env_id)
  File "/home/richard/anaconda3/envs/py35/lib/python3.5/site-packages/gym/envs/registration.py", line 164, in make
    return registry.make(id)
  File "/home/richard/anaconda3/envs/py35/lib/python3.5/site-packages/gym/envs/registration.py", line 122, in make
    env = spec.make()
  File "/home/richard/anaconda3/envs/py35/lib/python3.5/site-packages/gym/envs/registration.py", line 89, in make
    env = cls(**self._kwargs)
  File "/home/richard/anaconda3/envs/py35/lib/python3.5/site-packages/gym/envs/mujoco/reacher_pixel.py", line 10, in __init__
    mujoco_env.MujocoEnv.__init__(self, 'reacher.xml', 2)
  File "/home/richard/anaconda3/envs/py35/lib/python3.5/site-packages/gym/envs/mujoco/mujoco_env.py", line 39, in __init__
    observation, _reward, done, _info = self._step(np.zeros(self.model.nu))
  File "/home/richard/anaconda3/envs/py35/lib/python3.5/site-packages/gym/envs/mujoco/reacher_pixel.py", line 18, in _step
    ob = self._get_obs()
  File "/home/richard/anaconda3/envs/py35/lib/python3.5/site-packages/gym/envs/mujoco/reacher_pixel.py", line 40, in _get_obs
    print(np.shape(self._get_viewer()._read_pixels_as_in_window()))
  File "/home/richard/lib/mujoco-py/mujoco_py/mjviewer.py", line 218, in _read_pixels_as_in_window
    self.sim.render(resolution[0], resolution[1])
  File "mjsim.pyx", line 149, in mujoco_py.cymj.MjSim.render
  File "mjsim.pyx", line 151, in mujoco_py.cymj.MjSim.render
  File "mjrendercontext.pyx", line 43, in mujoco_py.cymj.MjRenderContext.__init__
  File "mjrendercontext.pyx", line 99, in mujoco_py.cymj.MjRenderContext._setup_opengl_context
  File "opengl_context.pyx", line 128, in mujoco_py.cymj.OffscreenOpenGLContext.__init__
RuntimeError: Failed to initialize OpenGL

My setup works for training and rendering video of the non-pixel Mujoco environment on my screen, but this '_read_pixels_as_in_window(self)', which I am using to access raw image data, fails. And actually even this method was working until I tried installing CUDA (which overwrote my nvidia-384 driver with nvidia-390') and installing CUDA broke everything, so now I think I rolled everything back to nvidia-384 properly and yet this read_pixels is still not working.

@febert
Copy link

febert commented Feb 26, 2018

Are there any updates on this?

@adonishong
Copy link

adonishong commented Mar 5, 2018

met same issue here, track into this file: ./mujoco_py/gl/eglshim.c
call eglGetError() with the place this issue happens(after eglMakeCurrent(eglDpy, EGL_NO_SURFACE, EGL_NO_SURFACE, eglCtx)), eglGetError returns 0x3002, EGL_BAD_ACCESS, no idea from this place...

mjpro150/sample/record with same logic works fine ...

@HailinRen
Copy link

Did anyone solve this problem?

@vitchyr
Copy link

vitchyr commented Apr 27, 2018

I've found that if I want to call env.render() then I need to set LD_PRELOAD to /usr/lib/x86_64-linux-gnu/libGLEW.so:/usr/lib/nvidia-384/libGL.so.

However, if I want to call env.sim.render(w, h), then I need to not set LD_PRELOAD (e.g. run unset LD_PRELOAD).

@lutein
Copy link

lutein commented Oct 31, 2018

@vitchyr Thx a lot!

@chenyiwen97
Copy link

I got the same problem,too.How to fix it?

@vitchyr
Copy link

vitchyr commented Mar 11, 2019

@chenyiwen97 have you tried the solution posted above?

@chenyiwen97
Copy link

@chenyiwen97 have you tried the solution posted above?

Yes.I add the 'export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libGLEW.so:/usr/lib/nvidia-415/libGL.so' to the bashrc, but it still doesn't work.

@chenyiwen97
Copy link

@chenyiwen97 have you tried the solution posted above?

Sorry, I misunderstood what you said. Now it works.Thanks a lot.

@beark007
Copy link

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/nvidia-384
This works for me.

@beark007
Copy link

beark007 commented May 17, 2019

when training, the following has to be commented, unless do testing.
export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libGLEW.so

@kracon7
Copy link

kracon7 commented May 28, 2019

Is there a solution to this (can't use env.render and env.sim.render in the same environment) yet?
I'm experiencing the same issue. And my current work around is to set and unset environment variable "LD_PRELOAD" everytime in python scripts.
Basically there is no way to call env.render() and env.sim.render(w, h) in the same environment because the first one requires export LD_PRELOAD=/usr/lib/...../libGLEW.so but the second one requires this line commented.

@luizmarao
Copy link

luizmarao commented Jun 14, 2019

After lots of trying and lots of reading, with no success, I tried (for no reason at all) something that worked!
Using the mode as rgb_array in env.sim.render(), I received a warning that mode should be offscreen or window. Offscreen was exactly the mode in that the error was happening... so I changed to window.
At first, the only change was that, immediately after loading the env, a render screen has shown up, without the error from offscreen mode. Then, without closing the render window, I decided to run the command env.sim.render() with offscreen mode on the python shell, and it worked!
I received the image without any error!
So I included in my code a line calling env.sim.render() with mode window before the line with mode offscreen, which gets the camera image.

my code lines (inside my gym environment):
self.sim.render(mode='window', camera_name='first-person', width=16, height=16, depth=False)
img = self.sim.render(mode='offscreen', camera_name='first-person', width=16, height=16, depth=False)

@huangjiancong1
Copy link

huangjiancong1 commented Apr 23, 2020

The most import is to check the usage inside env.render():

viewer =mujoco_py.MjRenderContextOffscreen(sim, dveice_id=)

or

viewer = mujoco_py.MjViewer(sim)

The second one should has a LD_PRELOAD= to /usr/lib/x86_64-linux-gnu/libGLEW.so:/usr/lib/nvidia-384/libGL.so as mentioned above.

@madhan001
Copy link

madhan001 commented Jul 2, 2020

undsetting LD_PRELOAD does't work for me, is there a workaround that doesn't involve it?
edit : This is an issue related to openGL and ubuntu nvidia drivers, move to a non ubuntu distro to fix this issue

@arthur801031
Copy link

I also had this problem, but it had to do with incorrect Ubuntu version. I had this error message using env.sim.render with Ubuntu 20.04, but once I reinstalled my machine with Ubuntu 18.04, the program ran perfectly.

@drozzy
Copy link

drozzy commented Jun 8, 2021

Here is a better solution I found: #390 (comment)

@geyang
Copy link

geyang commented Jan 3, 2022

Here is a full-writing targeting our HPC cluster: https://github.com/geyang/jaynes-starter-kit/tree/master/07_supercloud_setup

@axmav
Copy link

axmav commented May 3, 2022

I don't even have a /usr/lib/nvidia-384 folder. Only nvidia folder without any .so files inside. But actually CUDA is installed and working properly.
Normal rendering in widow is working but in offscreen context not.
it fails on: data = self.sim.render(width=width, height=height, camera_name=camera_name)
unset LD_PRELOAD helped

@zichunxx
Copy link

zichunxx commented May 12, 2022

I don't even have a /usr/lib/nvidia-384 folder. Only nvidia folder without any .so files inside. But actually CUDA is installed and working properly. Normal rendering in widow is working but in offscreen context not. it fails on: data = self.sim.render(width=width, height=height, camera_name=camera_name) unset LD_PRELOAD helped

I have the same issue as you, but unset LD_PRELOAD is useless for me.

@axmav
Copy link

axmav commented May 12, 2022

@QUIlToT as far as I understand you can not use the gym for rendering in window as well as in background at the same time on Ubuntu. You need to switch between using LD_PRELOAD and not.

@zichunxx
Copy link

@QUIlToT as far as I understand you can not use the gym for rendering in window as well as in background at the same time on Ubuntu. You need to switch between using LD_PRELOAD and not.

Thx! You made my day!

@Irismoon
Copy link

Irismoon commented Jul 6, 2022

I don't even have a /usr/lib/nvidia-384 folder. Only nvidia folder without any .so files inside. But actually CUDA is installed and working properly. Normal rendering in widow is working but in offscreen context not. it fails on: data = self.sim.render(width=width, height=height, camera_name=camera_name) unset LD_PRELOAD helped

Hi,
I'm running code below,
image

which throws RunTimeError at env.render(mode='rgb_array') like the figure below:
image

Would you like to give any advice?

Thanks,
Mango

@geng-haoran
Copy link

I was rendering on a remote server and met the same problem. I tried to open an VNC server with port 9 and export DISPLAY=:9 in the terminal, and then the problem was fixed.

@albee
Copy link

albee commented Mar 30, 2024

@huangjiancong1's and @vitchyr's answer guided me to the right solution on an ARM M1 Mac running an Ubuntu 20.04 VM. The NVIDIA drivers don't exist on this system (which has an Apple GPU), but making libGLX_mesa available for linking fixed things for me.

export LD_PRELOAD=/usr/lib/aarch64-linux-gnu/libGLEW.so:/usr/lib/aarch64-linux-gnu/libGLX_mesa.so.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests