mujoco-py icon indicating copy to clipboard operation
mujoco-py copied to clipboard

Linux Viewer Error: GLEW initalization error: Missing GL version

Open jonasschneider opened this issue 8 years ago • 49 comments

jonasschneider avatar Jun 28 '17 05:06 jonasschneider

Yes it is! I am getting the following error:

ERROR: GLEW initalization error: Missing GL version

Tried each and every possible GUI/OpenGL library update, with and without Anaconda on python 3.5.2. Seems there is some problem with Context of glfw or Initialization.

hmishra2250 avatar Jun 28 '17 23:06 hmishra2250

I have been trying to catch up with the cause of the error. I found that it's in the initialization of base class MjRenderContextWindow from which all viewer class inherits. Now, since this is packed as an Extension, my debugger can't see what is going inside. I even tried with glfw, different settings and using initializations as done in Mujoco_py==0.5.7, and the glfw seems to work well. I also tried adding some extra flags while building extensions such as -lGL and -lglew, but they didn't work because there is some other issue.

Another thing, I could not understand was what is the need of such kind of "building up and use" kind of structure, if ultimately we can't see the internal flow and debug. (Or maybe I am not experienced enough to know that we can!).

Please let me know what can be the possible problems and why did you prefer making extensions over just modules, so that I can also help in rectifying the problem.

Thanks

hmishra2250 avatar Jun 29 '17 20:06 hmishra2250

@hmishra2250 @jonasschneider Is there any update on how to get the Linux viewer GUI working? Or is there a recommended hack or work-around? I use Python 3.5 on Ubuntu 16.04 Thanks in anticipation

iretiayo avatar Jul 10 '17 16:07 iretiayo

+1

tartavull avatar Sep 02 '17 16:09 tartavull

An ugly workaround is to write your own viewer @iretiayo

import glfw
import numpy as np
from OpenGL.GLU import *
from OpenGL.GL import *

class Viewer():

    def __init__(self, sim):
        self.sim = sim

        if not glfw.init():
            return
        # Create a windowed mode window and its OpenGL context
        self._window = glfw.create_window(640, 480, "Hello World", None, None)
        if not self._window:
            glfw.terminate()
            return

        # Make the window's context current
        glfw.make_context_current(self._window)

    def render(self):
        # Make the window's context current
        glfw.make_context_current(self._window)
        if glfw.window_should_close(self._window):
            glfw.terminate()

        self.image = self.sim.render(640,480).astype(np.float) / 255.0

        # Render here, e.g. using pyOpenGL
        self.texture = glGenTextures(1)
        glEnable(GL_TEXTURE_2D)
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
        glBindTexture(GL_TEXTURE_2D, self.texture)
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
        glTexImage2D(GL_TEXTURE_2D, 0,
                     GL_RGB,
                     self.image.shape[1], self.image.shape[0], 0,
                     GL_RGB,
                     GL_FLOAT,
                     self.image)
        glDisable(GL_TEXTURE_2D)

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glClearColor(0., 0., 0., 0.)
        glClearDepth(1)
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        glBindTexture(GL_TEXTURE_2D, self.texture)
        glEnable(GL_TEXTURE_2D)
        # draw a textured quad, shrink it a bit so the edge is clear
        glBegin(GL_QUADS)
        glTexCoord2f(0., 0.)
        glVertex3f(-0.9, -0.9, 0.)
        glTexCoord2f(1., 0.)
        glVertex3f(0.9, -0.9, 0.)
        glTexCoord2f(1., 1.)
        glVertex3f(0.9, 0.9, 0.)
        glTexCoord2f(0., 1.)
        glVertex3f(-0.9, 0.9, 0.)
        glEnd()
        glDisable(GL_TEXTURE_2D)

        # Swap front and back buffers
        glfw.swap_buffers(self._window)

        # Poll for and process events
        glfw.poll_events()

tartavull avatar Sep 03 '17 03:09 tartavull

Keep in mind that this is really slow compared to the native mujoco visualizer

tartavull avatar Sep 03 '17 19:09 tartavull

+1

lukashermann avatar Sep 25 '17 11:09 lukashermann

+1

Kukanani avatar Oct 03 '17 18:10 Kukanani

+1

ethanabrooks avatar Oct 06 '17 22:10 ethanabrooks

The same error.

ViktorM avatar Oct 09 '17 01:10 ViktorM

Looks like it hasn't been fixed for almost 4 months. Are there any estimates when the bug can be fixed?

ViktorM avatar Oct 09 '17 01:10 ViktorM

I have some insight into this one. It looks like mujoco produces this error on my system when it is built with libglewosmesa and libOSMesa but succeeds when it's built with libglew instead. The problem is that I don't know how much of the code in mujoco-py depends on the mesa libraries and I don't really understand these graphics libraries that well.

I am getting some help from Emo on the MuJoCo forum. If I could also get some help from the mujoco-py team, I would be happy to work on a pull request.

ethanabrooks avatar Oct 13 '17 00:10 ethanabrooks

Agrre, looks like it is broken for 1.5. As I've installed older mujoco-py version for mujoco 1.3.1 and it worked out of the box.

ViktorM avatar Oct 13 '17 00:10 ViktorM

@lobachevzky so you mean you didn't get the error with mujoco-py if you build mujoco with libglew? It's weird because I can compile and run the c++ samples of mujoco 1.5 without getting an error, but mujoco-py crashes anyways.

lukashermann avatar Oct 13 '17 10:10 lukashermann

Yes exactly. In fact, that is how I was able to diagnose the problem. So in the makefile that comes with mujoco, the instruction for basic.cpp reads:

g++ -O2 -I../include -L../bin -std=c++11 -mavx basic.cpp -lmujoco150 -lGL -lglew ../bin/libglfw.so.3 -o ../bin/basic

This works fine for me. But if I replace the above with

g++ -O2 -I../include -L../bin -std=c++11 -mavx basic.cpp -lmujoco150 -lGL -lglewosmesa -lOSMesa ../bin/libglfw.so.3 -o ../bin/basic

and try to run basic:

~/.mujoco/mjpro150/bin
❯ LD_LIBRARY_PATH=. ./basic ../model/humanoid.xml
ERROR: GLEW initalization error: Missing GL version

Press Enter to exit ...

ethanabrooks avatar Oct 13 '17 15:10 ethanabrooks

It looks like this is related to making sure we both link and load the correct GL library.

Neither GLEW or GLFW are the underlying GL library, though osmesa is one (others include gpu-specific GL libraries).

What happens when you link/load with whatever your current system libGL is?

machinaut avatar Oct 26 '17 06:10 machinaut

What exactly is my current system libGL? It looks like the only libraries related to OpenGL on my LD_LIBRARY_PATH are the ones that come with mjPro150:

libglewegl.so
libglewosmesa.so
libglew.so
libglfw.so.3
libmujoco150nogl.so

ethanabrooks avatar Nov 01 '17 14:11 ethanabrooks

system gl should be libGL.so or similar. Are you able to use pyopengl (http://pyopengl.sourceforge.net/) or other openGL apps on the machine (glxinfo, glxgears) and see what GL libraries are loaded then.

machinaut avatar Nov 02 '17 18:11 machinaut

glxgears works find. I won't include all of glxinfo but everything seems to come from NVIDIA, including OpenGL. libGL.so is getting linked with the -lGL flag, which I use in both the working and non-working compile commands.

ethanabrooks avatar Nov 02 '17 18:11 ethanabrooks

I'll try to get a linux desktop with nvidia drivers to test on.

Is this happening for folks on machines with other GL drivers (e.g. mesa), too?

machinaut avatar Nov 02 '17 20:11 machinaut

I have libosmesa6 installed via apt. I tried uninstalling it and rebooting but it does not seem to have made any difference.

ethanabrooks avatar Nov 02 '17 20:11 ethanabrooks

One interesting fact is that make egl works fine in mjpro150/sample on my computer. So the issue is not with egl per se. I compared mjpro150/sample/record.cpp with eglshim.c and the two are very similar, although eglshim.c includes a lot of additional stuff.

ethanabrooks avatar Nov 02 '17 21:11 ethanabrooks

Hi @tartavull, Are you sure that the code that you wrote is correct? It's showing me this runtime error:

Found 1 GPUs for rendering. Using device 0.
Could not make EGL context current
Traceback (most recent call last):
  File "/home/amin/Projects/baselines/test.py", line 239, in <module>
    viewer.render()
  File "/home/amin/Projects/baselines/test.py", line 28, in render
    self.image = self.sim.render(640,480).astype(np.float) / 255.0
  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

donamin avatar Nov 07 '17 12:11 donamin

@lobachevzky @machinaut I 'm getting the same ERROR. ERROR: GLEW initalization error: Missing GL version How can I fix it? Seems there is a problem with NIVIDIA GPU.... Thanks

Jerryxiaoyu avatar Dec 04 '17 09:12 Jerryxiaoyu

@Jerryxiaoyu actually I believe that it has something to do with simultaneously compiling EGL and GLFW. I eventually wrote my own little wrapper script for mujoco which was mostly suited to my purposes but is general purpose enough that you are welcome to take a look: https://github.com/lobachevzky/mujoco

ethanabrooks avatar Dec 04 '17 12:12 ethanabrooks

@lobachevzky Thanks. Actually it has nothing to do with GPU because I tried to force to use CPU and got the same problem. But it's wired because there seems OK on another computer with the same enviornment (Ununtu 16.04 /Anaconda3)without Nvidia Titan 1080Ti.....

Jerryxiaoyu avatar Dec 05 '17 03:12 Jerryxiaoyu

@Jerryxiaoyu make sure you call make clean and then recompile.

My advice would be to make sure that you can compile the sample scripts that come with mujoco:

cd ~/.mujoco/mjpro150/sample/
make

If that works, see if using the the libraries that are specified in that Makefile work with mujoco-py. You would need to change this line assuming that you are using linux.

I don't know exactly what is causing these problems, but there are a few likely culprits:

  • As indicated by the line that I linked to, mujoco-py uses slightly different libraries than mujoco.
  • It uses python GLFW instead of the GLFW that comes packaged with mujoco.
  • The GPU version tries to use GLFW and EGL concurrently.

ethanabrooks avatar Dec 06 '17 01:12 ethanabrooks

@lobachevzky Following your advice, I checked the Makefile and it works. Then I modified two lines according to your pull request #145. It solved my issue. Thank you for your help.

Jerryxiaoyu avatar Dec 06 '17 07:12 Jerryxiaoyu

This error still occurs and unfortunately none of the suggested fixes seem to work for me. I eventually worked around it by disabling my Nvidia GPU and using the integrated Intel GPU.

janniseis avatar Apr 11 '18 12:04 janniseis

I have the same issue. Can we please get an update on this? This issue makes mujoco-py all but unusable.

Version 131 still works for me, so if anyone needs a workaround downgrading seems to be an option.

SanderDalm avatar Apr 14 '18 18:04 SanderDalm