'cannot run gazebo9 on docker with privileged on ubuntu 18.04

I am stuck on this for quite a while now i have tried searching and trying stuff but i am getting nowhere. My setup is as follows:

Host

linux Distro: Archlinux kernel version: 5.14.2 docker version: 20.10.8, build 3967b7d28e nvidia driver version: 470.63.01-1 nvidia container toolkit version: 1.5.0-2 , cgroups disabled. amd gpu driver: xf86-video-amdgpu 21.0.0-1

Container

base image: ubuntu:18.04 command line : docker run -it --rm --privileged --gpus all -e DISPLAY=$DISPLAY -e XAUTHORITY=~/.Xauthority --network host --volume /tmp/.X11-unix/:/tmp/.X11-unix --volume $XAUTHORITY:/root/.Xauthority gazebo:libgazebo9-bionic gazebo

Expected results

expected gazebo window to open with hardware acceleration, using privileged access.

Actual results

On using --privileged:

si_init_perfcounters: max_sh_per_se = 2 not supported (inaccurate performance counters)
X Error of failed request:  BadAlloc (insufficient resources for operation)
  Major opcode of failed request:  149 ()
  Minor opcode of failed request:  2
  Serial number of failed request:  35
  Current serial number in output stream:  36 

Without --privileged and specifying graphic cards in --device manually: gazebo window opens up with hardware acceleration and works smoothly as expected.

Detailed description

I was actually trying to run gazebo version 9 in a custom image which i had created using ubuntu:18.04 as base image. i referred to gazebo:libgazebo9-bionic,nvidia/cuda:11.4.1-cudnn8-devel-ubuntu18.04 and ros:melodic-desktop while writing the dockerfile. i even tried the same thing for gazebo 11 on the same base image and got the same issue as above. Whereas the exactly similar setup for ubuntu foxy works smoothly. i really need to use privileged because i am going to be working on hardware for a lot of time. please help me on how should this be fixed. thanks alot

P.S. Other GUI applications (rviz,moveit,etc) are running without any issues. Im getting this issue with gazebo only.



Solution 1:[1]

Ok found the solution!

Gazebo was working on osrf/ros:noetic-desktop-full but not on osrf/ros:melodic-desktop-full.

I got the exact same error:

X Error of failed request:  BadAlloc (insufficient resources for operation)
  X Error of failed request:  BadAlloc (insufficient resources for operation)
  Major opcode of failed request:  149 ()

The solution was to update the MESA drivers on the ros:melodic image from version Mesa 20.0.8 to Mesa 22.0.2.

sudo add-apt-repository ppa:kisak/kisak-mesa -y
sudo apt update
sudo apt upgrade -y

If you want to check your current Mesa version:

sudo apt install mesa-utils
glxinfo | grep Mesa

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Frank