mujoco icon indicating copy to clipboard operation
mujoco copied to clipboard

GLFW Issue on Ubuntu 24.04

Open david-dorf opened this issue 10 months ago • 3 comments

Intro

Hi!

I am a robotics engineer at Triton Systems and I use MuJoCo for simulation.

My setup

MuJoCo 3.2.7 on PyPi (Python), AMD64, Ubuntu 24.04

What's happening? What did you expect?

Running within a Bazel module:

INFO: Running command line: bazel-bin/mujoco_py /home/david/.cache/bazel/_bazel_david/f695e6f26414630bc7daef67dcbe0426/execroot/_main/bazel-out/k8-fastbuild/bin/mujoco_py.runfiles/.mujoco_py.venv/lib/python3.12/site-packages/glfw/init.py:917: GLFWError: (65548) b'Wayland: The platform does not provide the window position' warnings.warn(message, GLFWError)

Attempts to import GLFW directly haven't worked to eliminate this from popping up every time the viewer is opened.

Steps for reproduction

  1. Run the code below.
  2. Get the warning message.

Minimal model for reproduction

Shouldn't need this if you import the robot_descriptions package as follows

Code required for reproduction


import time
import mujoco
import mujoco.viewer
from robot_descriptions.loaders.mujoco import load_robot_description


model = load_robot_description("panda_mj_description")
data = mujoco.MjData(model)

with mujoco.viewer.launch_passive(model, data) as viewer:
    try:
        while viewer.is_running():
            step_start = time.time()
            mujoco.mj_step(model, data)
            with viewer.lock():
                viewer.opt.flags[mujoco.mjtVisFlag.mjVIS_CONTACTPOINT] = int(data.time % 2)
            viewer.sync()
            time_until_next_step = model.opt.timestep - (time.time() - step_start)
            if time_until_next_step > 0:
                time.sleep(time_until_next_step)
    except KeyboardInterrupt:
        pass

Confirmations

david-dorf avatar Jan 28 '25 19:01 david-dorf

Hi @david-dorf . I think I ran into a similar issue the other day when using wayland. Could you check which version of glfw are you using?

pip freeze | grep glfw

If you're using version 1.12.0 then you'll just have to update to the latest version (current is 2.8.0). I get the same warning, but the visualizer opens normally. I got this issue bc it seems that the package from dm_control uses an old version of glfw in their requirements.txt file.

Hope this solves your issue.

wpumacay avatar Feb 02 '25 19:02 wpumacay

It's version 2.8.0, but it's just that the warning is a little annoying - not really a major issue stopping me from doing anything. If this is already expected then I can close this issue.

david-dorf avatar Feb 05 '25 16:02 david-dorf

I have glfw version 2.7.0 and I get a GLFWError: (65544) b'Wayland: Window position retrieval not supported' warnings.warn(message, GLFWError) and it actually makes it so that none of the buttons on the MJ visualiser work.

Adding an environment variable to force GLFW to use x11 instead works in fixing both the warning and the issues with the buttons: export PYGLFW_LIBRARY_VARIANT=x11. If it's just an annoying warning and you have XWayland, maybe just use that.

LaVieEstDure avatar Feb 06 '25 06:02 LaVieEstDure

cc @m01

yuvaltassa avatar Jul 28 '25 10:07 yuvaltassa

@m01 is this now fixed?

yuvaltassa avatar Sep 01 '25 12:09 yuvaltassa

Firstly, thank you for the repro.

Sadly it's not fixed. But I know what the issue is.

This calls to glfwGetWindowPos here: https://github.com/google-deepmind/mujoco/blob/8acd83f3173df98da3379f2aa96f8d76b85c3741/simulate/glfw_adapter.cc#L67-L69 (and here: https://github.com/google-deepmind/mujoco/blob/8acd83f3173df98da3379f2aa96f8d76b85c3741/simulate/glfw_adapter.cc#L185-L196)

presumably ends up calling this code here https://github.com/glfw/glfw/blob/63a7e8b7f82497b0459acba5c1ce7f39aa2bc0e8/src/wl_window.c#L2288-L2295:

void _glfwGetWindowPosWayland(_GLFWwindow* window, int* xpos, int* ypos)
{
    // A Wayland client is not aware of its position, so just warn and leave it
    // as (0, 0)

    _glfwInputError(GLFW_FEATURE_UNAVAILABLE,
                    "Wayland: The platform does not provide the window position");
}

which triggers the Wayland: The platform does not provide the window position message.

Skipping Glfw().glfwGetWindowPos(...) would fix the issue:

  • This could be conditional on glfwGetPlatform() indicating we're on Wayland, although that'd be making assumptions about the underlying GLFW implementation, which isn't ideal. glfwGetPlatform would also need adding to the dynamic dispatch table in ./simulate/glfw_dispatch.{h|cc}.
  • The window_pos_ private member variable seems to be used for restoring the window after toggling fullscreen, I'm not sure if skipping it unconditionally would cause issues on other platforms, that might need testing.

m01 avatar Sep 01 '25 15:09 m01

@m01 is this now fixed?

From what I can tell, this has nothing to do with GLFW. The error happens independently of the windowing library. I for example, when I try to use the Python viewer, get the error:

/home/davidhozic/.venv/lib/python3.13/site-packages/glfw/init.py:917: GLFWError: (65548) b'Wayland: The platform does not provide the window position' warnings.warn(message, GLFWError)

When I try to use a completely different windowing library (winit + glutin) at my custom viewer, I get the the following error (warning):

Tue Oct 28 20:12:00 2025 WARNING: OpenGL error 0x502 in or before mjr_makeContext

This happens when I try to call mjr_makeContext through the C API. Code 0x502 is the value of GL_INVALID_OPERATION, so I assume MuJoCo itself needs to do other adjustments for wayland.

The issues only appear on the Wayland platform. X11 works fine.

I also don't call GetWindowPosition anywhere.

davidhozic avatar Oct 28 '25 19:10 davidhozic

Solution until Wayland itself adds support for the missing function: WAYLAND_DISPLAY= XDG_SESSION_TYPE=x11 python -m mujoco.viewer

This will force X11 to be used for MuJoCo.

davidhozic avatar Oct 28 '25 19:10 davidhozic