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

crash when using bgfx and wayland #5693

Closed
belegdol opened this issue Sep 29, 2019 · 17 comments
Closed

crash when using bgfx and wayland #5693

belegdol opened this issue Sep 29, 2019 · 17 comments
Labels

Comments

@belegdol
Copy link
Contributor

Hello,

bgfx and wayland seem to be incompatible at the moment. I can run -videodriver x11 -video bgfx or -videodriver wayland -video gl, but trying to run -videodriver wayland -video bgfx crashes mame:

$ gdb mame
GNU gdb (GDB) Fedora 8.3-6.fc30
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from mame...
Reading symbols from /usr/lib/debug/usr/bin/mame-0.214-1.fc30.x86_64.debug...
(gdb) run -verbose -videodriver wayland -video bgfx
Starting program: /usr/bin/mame -verbose -videodriver wayland -video bgfx
warning: Loadable section ".note.gnu.property" outside of ELF segments
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
warning: Loadable section ".note.gnu.property" outside of ELF segments
warning: Loadable section ".note.gnu.property" outside of ELF segments
warning: Loadable section ".note.gnu.property" outside of ELF segments
warning: Loadable section ".note.gnu.property" outside of ELF segments
warning: Loadable section ".note.gnu.property" outside of ELF segments
warning: Loadable section ".note.gnu.property" outside of ELF segments
warning: Loadable section ".note.gnu.property" outside of ELF segments
warning: Loadable section ".note.gnu.property" outside of ELF segments
warning: Loadable section ".note.gnu.property" outside of ELF segments
Attempting load of mame.ini
Parsing mame.ini
Attempting load of mame.ini
Parsing mame.ini
Starting plugin data...
Attempting load of mame.ini
Parsing mame.ini
Attempting load of mame.ini
Parsing mame.ini
Setting SDL videodriver 'wayland' ...
Available videodrivers: x11 wayland KMSDRM dummy 
Current Videodriver: wayland
	Display #0
		Renderdrivers:
			    opengl (0x0)
			 opengles2 (0x0)
			  software (0x0)
Available audio drivers: 
	pulseaudio          
	alsa                
	dsp                 
	jack                
	disk                
	dummy               
Build version:      0.214 (unknown)
Build architecure:  
Build defines 1:    SDLMAME_UNIX=1 SDLMAME_X11=1 SDLMAME_LINUX=1 
Build defines 1:    LSB_FIRST=1 PTR64=1 
SDL/OpenGL defines: SDL_COMPILEDVERSION=2010 USE_OPENGL=1 
Compiler defines A: __GNUC__=9 __GNUC_MINOR__=2 __GNUC_PATCHLEVEL__=1 __VERSION__="9.2.1 20190827 (Red Hat 9.2.1-1)" 
Compiler defines B: __amd64__=1 __x86_64__=1 __unix__=1 
Compiler defines C: _FORTIFY_SOURCE=2 __USE_FORTIFY_LEVEL=2 
Enter init_monitors
Adding monitor screen0 (1920 x 1080)
Leave init_monitors
Enter sdlwindow_init

Hints:
	SDL_FRAMEBUFFER_ACCELERATION             (null)
	SDL_RENDER_DRIVER                        (null)
	SDL_RENDER_OPENGL_SHADERS                (null)
	SDL_RENDER_SCALE_QUALITY                 (null)
	SDL_RENDER_VSYNC                         (null)
	SDL_VIDEO_X11_XVIDMODE                   (null)
	SDL_VIDEO_X11_XINERAMA                   (null)
	SDL_VIDEO_X11_XRANDR                     (null)
	SDL_GRAB_KEYBOARD                        (null)
	SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS         (null)
	SDL_IOS_IDLE_TIMER_DISABLED              (null)
	SDL_IOS_ORIENTATIONS                     (null)
	SDL_XINPUT_ENABLED                       (null)
	SDL_GAMECONTROLLERCONFIG                 (null)
	SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS     (null)
	SDL_ALLOW_TOPMOST                        (null)
	SDL_TIMER_RESOLUTION                     (null)
	SDL_RENDER_DIRECT3D_THREADSAFE           (null)
	SDL_VIDEO_ALLOW_SCREENSAVER              (null)
	SDL_ACCELEROMETER_AS_JOYSTICK            (null)
	SDL_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK   (null)
	SDL_VIDEO_WIN_D3DCOMPILER                (null)
	SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT      (null)
	SDL_VIDEO_MAC_FULLSCREEN_SPACES          (null)
	SDL_MOUSE_RELATIVE_MODE_WARP             (null)
	SDL_RENDER_DIRECT3D11_DEBUG              (null)
	SDL_VIDEO_HIGHDPI_DISABLED               (null)
	SDL_WINRT_PRIVACY_POLICY_URL             (null)
	SDL_WINRT_PRIVACY_POLICY_LABEL           (null)
	SDL_WINRT_HANDLE_BACK_BUTTON             (null)
Leave sdlwindow_init
Enter sdl_info::create
Missing separate debuginfo for /lib64/libEGL.so.1
Try: dnf --enablerepo='*debug*' install /usr/lib/debug/.build-id/4f/067a146109f7476cfe34d1f74df38753471b6c.debug
warning: Loadable section ".note.gnu.property" outside of ELF segments
warning: Loadable section ".note.gnu.property" outside of ELF segments
warning: Loadable section ".note.gnu.property" outside of ELF segments
Missing separate debuginfo for /lib64/libX11-xcb.so.1
Try: dnf --enablerepo='*debug*' install /usr/lib/debug/.build-id/cc/697ed458ee0a93c262f328643f40afdab6baaf.debug
warning: Loadable section ".note.gnu.property" outside of ELF segments
warning: Loadable section ".note.gnu.property" outside of ELF segments
warning: Loadable section ".note.gnu.property" outside of ELF segments
[New Thread 0x7fffed617700 (LWP 11118)]
[New Thread 0x7fffe49b6700 (LWP 11119)]

Thread 3 "mame" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffe49b6700 (LWP 11119)]
0x00007ffff6837aa1 in _XSend (dpy=dpy@entry=0x555566dc91f0, data=data@entry=0x0, size=size@entry=0) at xcb_io.c:464
464		if(dpy->bufptr == dpy->buffer && !size)
Missing separate debuginfos, use: dnf debuginfo-install SDL2-2.0.10-1.fc30.x86_64 SDL2_ttf-2.0.15-2.fc30.x86_64 alsa-lib-1.1.9-1.fc30.x86_64 bzip2-libs-1.0.6-29.fc30.x86_64 elfutils-libelf-0.177-1.fc30.x86_64 expat-2.2.8-1.fc30.x86_64 flac-libs-1.3.2-10.fc30.x86_64 fontconfig-2.13.1-9.fc30.x86_64 freetype-2.9.1-7.fc30.x86_64 glib2-2.60.7-1.fc30.x86_64 graphite2-1.3.13-1.fc30.x86_64 harfbuzz-2.3.1-1.fc30.x86_64 jack-audio-connection-kit-1.9.12-8.fc30.x86_64 libXau-1.0.9-1.fc30.x86_64 libXi-1.7.10-1.fc30.x86_64 libdrm-2.4.99-1.fc30.x86_64 libedit-3.1-27.20190324cvs.fc30.x86_64 libffi-3.1-19.fc30.x86_64 libgcc-9.2.1-1.fc30.x86_64 libgcrypt-1.8.5-1.fc30.x86_64 libjpeg-turbo-2.0.2-1.fc30.x86_64 libogg-1.3.3-2.fc30.x86_64 libpng-1.6.36-1.fc30.x86_64 libselinux-2.9-3.1.fc30.x86_64 libstdc++-9.2.1-1.fc30.x86_64 libwayland-client-1.17.0-1.fc30.x86_64 libwayland-server-1.17.0-1.fc30.x86_64 libxcb-1.13.1-2.fc30.x86_64 libxkbcommon-0.8.3-1.fc30.x86_64 libxshmfence-1.3-4.fc30.x86_64 llvm-libs-8.0.0-6.fc30.x86_64 lua-libs-5.3.5-5.fc30.x86_64 mesa-libEGL-19.1.7-1.fc30.x86_64 mesa-libglapi-19.1.7-1.fc30.x86_64 ncurses-libs-6.1-10.20180923.fc30.x86_64 opus-1.3.1-1.fc30.x86_64 pcre-8.43-2.fc30.x86_64 pcre2-utf16-10.33-14.fc30.x86_64 portaudio-19-29.fc30.x86_64 portmidi-217-27.fc30.x86_64 pugixml-1.9-3.fc30.x86_64 qt5-qtbase-5.12.4-4.fc30.x86_64 qt5-qtbase-gui-5.12.4-4.fc30.x86_64 sqlite-libs-3.26.0-6.fc30.x86_64 systemd-libs-241-12.git1e19bcd.fc30.x86_64 utf8proc-2.3.0-1.fc30.x86_64 xz-libs-5.2.4-5.fc30.x86_64 zlib-1.2.11-18.fc30.x86_64
(gdb) bt
#0  0x00007ffff6837aa1 in _XSend (dpy=dpy@entry=0x555566dc91f0, data=data@entry=0x0, size=size@entry=0) at xcb_io.c:464
#1  0x00007ffff6837f24 in _XFlush (dpy=0x555566dc91f0) at xcb_io.c:516
#2  0x00007ffff683aafd in _XGetRequest (dpy=dpy@entry=0x555566dc91f0, type=type@entry=98 'b', len=len@entry=8) at XlibInt.c:1717
#3  0x00007ffff682e051 in XQueryExtension (dpy=dpy@entry=0x555566dc91f0, name=name@entry=0x7ffff60dc006 "GLX", 
    major_opcode=major_opcode@entry=0x7fffe0000c34, first_event=first_event@entry=0x7fffe49b55b4, 
    first_error=first_error@entry=0x7fffe0000c38) at QuExt.c:44
#4  0x00007ffff60d7e8d in InitDisplayInfoEntry (dpy=0x555566dc91f0) at libglxmapping.c:645
#5  __glXLookupDisplay (dpy=<optimized out>, dpy@entry=0x555566dc91f0) at libglxmapping.c:737
#6  0x00007ffff60d3e09 in glXQueryVersion (dpy=0x555566dc91f0, major=0x7fffe49b5670, minor=0x7fffe49b5674) at libglx.c:1170
#7  0x000055556103760c in bgfx::gl::GlContext::create () at ../../../../../3rdparty/bgfx/src/glcontext_glx.cpp:81
#8  0x0000555561020c8e in bgfx::gl::RendererContextGL::setRenderContextSize ()
    at ../../../../../3rdparty/bgfx/src/renderer_gl.cpp:3308
#9  bgfx::gl::RendererContextGL::init () at ../../../../../3rdparty/bgfx/src/renderer_gl.cpp:1771
#10 0x000055556101d9f6 in bgfx::gl::rendererCreate () at ../../../../../3rdparty/bgfx/src/renderer_gl.cpp:3893
#11 0x0000555560ff8bbd in bgfx::rendererCreate () at ../../../../../3rdparty/bgfx/src/bgfx.cpp:2498
#12 0x0000555561006cb9 in bgfx::Context::rendererExecCommands () at ../../../../../3rdparty/bgfx/src/bgfx.cpp:2549
#13 0x0000555561006d3d in bgfx::Context::renderFrame () at ../../../../../3rdparty/bgfx/src/bgfx.cpp:2201
#14 0x0000555561006e7a in bgfx::renderFrame () at ../../../../../3rdparty/bgfx/src/bgfx.cpp:1355
#15 0x000055556101006a in bgfx::Context::renderThread () at ../../../../../3rdparty/bgfx/src/bgfx_p.h:2734
#16 0x000055556105c503 in bx::Thread::entry () at ../../../../../3rdparty/bx/src/thread.cpp:294
#17 bx::ThreadInternal::threadFunc () at ../../../../../3rdparty/bx/src/thread.cpp:89
#18 0x00007ffff7dd74c0 in start_thread (arg=<optimized out>) at pthread_create.c:479
#19 0x00007ffff6367553 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
@rb6502
Copy link
Contributor

rb6502 commented Sep 29, 2019

This is an upstream BGFX issue; they lack Wayland support.

The bug there for it is bkaradzic/bgfx#1007

@couriersud
Copy link
Contributor

@belegdol The upstream bug has been closed. Is this now working?

@belegdol
Copy link
Contributor Author

I have since switched back to the nvidia binary driver so I will need some time to re-test. If I recall correctly, the crashes were still happening.
Last time I looked into this the two wayland-related bgfx commits, i.e. bkaradzic/bgfx@2b6d4cf and bkaradzic/bgfx@ff13e73, predominantly touched the examples and the only non-scripts bgfx change to src/glcontext_egl.h was effectively reverted by the second commit.
I believe that an equivalent linking change has been achieved when the odroid n2 fixes were committed:

if _OPTIONS["NO_X11"]~="1" then
links {
"X11",
"Xinerama",
}
else
if _OPTIONS["targetos"]=="linux" or _OPTIONS["targetos"]=="netbsd" or _OPTIONS["targetos"]=="openbsd" then
links {
"EGL",
}
end
end

I think that what is left is to write the wayland-specific code as was done for bgfx examples. Or am I wrong?

@belegdol
Copy link
Contributor Author

Is anyone familiar with bgfx examples? I built bgfx upstream adding --with-wayland to the genie scripts, but the example window still ran under xwayland according to xeyes.

@MooglyGuy
Copy link
Contributor

I have a friend with a relevant setup. I'll see what we can work out this weekend.

@belegdol
Copy link
Contributor Author

belegdol commented Jan 13, 2021

I got a new laptop with an AMD Renoir 4500U APU in it which means it defaults to running Gnome under Wayland. With opengl bgfx backend I get around 110 % speed with umk3, windowed or not. Switching to full screen does make the speed dip transiently but it recovers. With vulkan backend umk3 runs at around 500 % windowed and around 50 % full screen. Not sure if xwayland is to blame here, but I am putting the information out there in case anybody encounters similar problems.

@angelosa angelosa added the bgfx label Feb 4, 2021
@belegdol
Copy link
Contributor Author

I have now managed to build bgfx examples with wayland enabled - the key was to use --with-sdl in addition to --with-wayland. The bad news is that the examples do not run:

$ ../../.build/linux64_gcc/bin/examplesRelease 
libGL error: failed to create drawable
libGL error: failed to create drawable
X Error of failed request:  GLXBadContext
  Major opcode of failed request:  150 (GLX)
  Minor opcode of failed request:  26 (X_GLXMakeContextCurrent)
  Serial number of failed request:  221
  Current serial number in output stream:  221

@belegdol
Copy link
Contributor Author

belegdol commented Jul 23, 2021

This issue might become more important with nvidia finally supporting xwayland as of 470.xx drivers. This was the last (or one of the last) issues holding back the enablement of wayland on nvidia drivers by default.

ETA: it looks like gdm will no longer disable wayland on nvidia moving forward:
https://gitlab.gnome.org/GNOME/gdm/-/commit/9ecf839913846211ffe10e1243a360c3cb66ff61

@belegdol
Copy link
Contributor Author

belegdol commented Aug 19, 2021

I checked with xeyes and using

mame -videodriver wayland -video opengl

actually does result in a wayland window being drawn as of SDL-2.0.16, albeit without a window decoration. This indicates that at least the SDL part is capable of wayland.

@belegdol
Copy link
Contributor Author

belegdol commented May 2, 2022

Fedora's SDL2-2.0.22 has switched to wayland by default [1]. This puts me in an unfortunate situation as I have recently switched mame video output to use bgfx by default to follow upstream. With SDL2 using wayland by default, mame is unusable with default settings. While I have filed a bug against SDL2 [2], if its maintainer decides to keep the change, this might leave me no choice but to revert back to opengl video output as standard. What are the chances of bgfx' wayland support getting fixed up in the near future?
[1] https://src.fedoraproject.org/rpms/SDL2/blob/rawhide/f/SDL2-2.0.22-prefer-wayland.patch
[2] https://bugzilla.redhat.com/show_bug.cgi?id=2081093

@Conan-Kudo
Copy link

I'm able to compile bgfx from mainline with wayland enabled on Fedora 36:

First, install build dependencies:

$ sudo dnf --assumeyes install make gcc gcc-c++ SDL2-devel wayland-devel libglvnd-devel

Second, clone the repos:

$ git clone https://github.com/bkaradzic/bx.git
$ git clone https://github.com/bkaradzic/bimg.git
$ git clone https://github.com/bkaradzic/bgfx.git

Third, build the code:

$ cd bgfx
$ sed -e "283d" -i examples/07-callback/callback.cpp
$ make EXTRA_GENIE_ARGS="--with-sdl --with-wayland" linux-debug64 -j12

The sed line is for the following patch to get rid of a use-after-free error:

diff --git a/examples/07-callback/callback.cpp b/examples/07-callback/callback.cpp
index 52cc283df..240e4e96c 100644
--- a/examples/07-callback/callback.cpp
+++ b/examples/07-callback/callback.cpp
@@ -280,7 +280,6 @@ public:
 		if (kNaturalAlignment >= _align)
 		{
 			void* ptr = ::realloc(_ptr, _size);
-			bx::debugPrintf("%s(%d): REALLOC %p (old %p) of %d byte(s)\n", _file, _line, ptr, _ptr, _size);
 
 			if (NULL == _ptr)
 			{

It seems to compile for me? @bkaradzic seems to have Wayland support in here. However, I can't run the examples as it crashes trying to load Vulkan (I can't figure out how to force a particular render backend).

@belegdol
Copy link
Contributor Author

belegdol commented May 3, 2022

you can force gl backend by running exampes with --gl argument, like so:
./../../.build/linux64_gcc/bin/examplesDebug --gl
I was not able to get this to work either.

@Conan-Kudo
Copy link

Maybe it's related to all the vendored copies of libraries in bgfx rather than using system copies? I'm not sure why this would fail so much like this...

@bkaradzic
Copy link
Contributor

use-after-free error

Where do you see use-after-free?!

@Conan-Kudo
Copy link

use-after-free error

Where do you see use-after-free?!

When I try to follow the steps without patching out the line in the callback example, gcc throws an error saying that _ptr is being used after it has already been freed.

@smf-
Copy link
Member

smf- commented May 4, 2022 via email

@belegdol
Copy link
Contributor Author

Fixed by #11451

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

No branches or pull requests

8 participants