WSL rviz display error when launching application (qt.qpa.screen)

Viewed 1189

I am using ROS Melodic on Ubuntu 18.04 with gazebo9 and Xlaunch. I have been able to launch an empty workspace of gazebo but for some reason when I run rosrun rviz rviz, I get this error message:

QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
qt.qpa.screen: QXcbConnection: Could not connect to display
Could not connect to any X display.

I have roscore running with no errors, so I dont believe its that which is causing the problem This is the full script:

Gazebo

root@DESKTOP-GFT05HU:/mnt/c/Users/Frank# export GAZEBO_IP=127.0.0.1
root@DESKTOP-GFT05HU:/mnt/c/Users/Frank# export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
root@DESKTOP-GFT05HU:/mnt/c/Users/Frank# export LIBGL_ALWAYS_INDIRECT=0
root@DESKTOP-GFT05HU:/mnt/c/Users/Frank# gazebo      
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4528:(_snd_config_evaluate) function 
snd_func_card_driver returned error: No such file or 
directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4528:(_snd_config_evaluate) function 
snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4528:(_snd_config_evaluate) function 
snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM default
AL lib: (EE) ALCplaybackAlsa_open: Could not open playback device 'default': No such file or directory    
[Err] [REST.cc:205] Error in REST request

libcurl: (51) SSL: no alternative certificate subject name matches target host name 'api.ignitionfuel.org'

Rviz:

root@DESKTOP-GFT05HU:/mnt/c/Users/Frank# rosrun rviz rviz
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
qt.qpa.screen: QXcbConnection: Could not connect to display
Could not connect to any X display.
2 Answers

Since WSL runs on top of the windows hypervisor you should treat the terminal like it has no direct knowledge of your display. To get this to work you need to do 2 things.

  1. You need to download a windows X Server client. I personally use XMing.

  2. Set your environment variable DISPLAY. Such as export DISPLAY=localhost:0.0

Edit: After doing some digging this issue is caused by how libGL interacts with the specific x server you're running. You have two options to fix this:

  1. You run XMing instead of of XLaunch

  2. If you want to keep using XLaunch under the "Additional Parameters for VcXsrv" add -nowgl

Related