-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
examples crash with SDL/wayland when using default (vulkan) renderer #2416
Comments
I just checked and examples compiled with --with-sdl alone do run (using the default x11 SDL_VIDEODRIVER). |
With --gl the backtrace is slightly different:
|
It looks like bgfx is trying to run using GLX instead of EGL. More and more linux distros are moving to Wayland (therefore EGL) and I think this should be addressed for linux platforms. Ubuntu now comes with Wayland enabled by default. From bgfx code I see that EGL is enabled only on mobile platforms, but we need to have a way to switch between those on desktop platforms as well ... It would be even perfect to be able to select GLX or EGL in runtime (during initialization), but I personally would be happy to have compile-time selection. I think we should request this as a new feature, rather then bug report ? |
Do you know how to detect which WM is currently used? You can send PR. |
SDL-2.0.18 does not help. I tried forcing the use of EGL as @charlieamer suggested with a crude patch, but I could not get bgfx to build: diff --git a/src/renderer_gl.h b/src/renderer_gl.h
index 83b271201..fe52de7bc 100644
--- a/src/renderer_gl.h
+++ b/src/renderer_gl.h
@@ -6,14 +6,17 @@
#ifndef BGFX_RENDERER_GL_H_HEADER_GUARD
#define BGFX_RENDERER_GL_H_HEADER_GUARD
-#define BGFX_USE_EGL (BGFX_CONFIG_RENDERER_OPENGLES && (0 \
+#define BGFX_USE_EGL ((BGFX_CONFIG_RENDERER_OPENGLES && (0 \
|| BX_PLATFORM_ANDROID \
|| BX_PLATFORM_BSD \
|| BX_PLATFORM_LINUX \
|| BX_PLATFORM_NX \
|| BX_PLATFORM_RPI \
|| BX_PLATFORM_WINDOWS \
- ) )
+ ) ) \
+ || (BGFX_CONFIG_RENDERER_OPENGL && (0 \
+ || BX_PLATFORM_LINUX \
+ ) ) )
#define BGFX_USE_HTML5 (BGFX_CONFIG_RENDERER_OPENGLES && (0 \
|| BX_PLATFORM_EMSCRIPTEN \
@@ -25,9 +28,8 @@
#define BGFX_USE_GLX (BGFX_CONFIG_RENDERER_OPENGL && (0 \
|| BX_PLATFORM_BSD \
- || BX_PLATFORM_LINUX \
) )
-
+
#define BGFX_USE_GL_DYNAMIC_LIB (0 \
|| BX_PLATFORM_BSD \
|| BX_PLATFORM_LINUX \ |
I managed to get EGL to build under Linux with this crude patch: 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)
{
diff --git a/makefile b/makefile
index 5fd42a7b7..fe20eedd9 100644
--- a/makefile
+++ b/makefile
@@ -104,7 +104,7 @@ wasm-release: .build/projects/gmake-wasm ## Build - Emscripten Release
wasm: wasm-debug wasm-release ## Build - Emscripten Debug and Release
.build/projects/gmake-linux:
- $(GENIE) --with-tools --with-combined-examples --with-shared-lib --gcc=linux-gcc gmake
+ $(GENIE) --with-tools --with-combined-examples --with-shared-lib --with-sdl --with-wayland --gcc=linux-gcc gmake
linux-debug64: .build/projects/gmake-linux ## Build - Linux x64 Debug
$(MAKE) -R -C .build/projects/gmake-linux config=debug64
linux-release64: .build/projects/gmake-linux ## Build - Linux x64 Release
diff --git a/scripts/bgfx.lua b/scripts/bgfx.lua
index 69f89958c..e2ae534fc 100644
--- a/scripts/bgfx.lua
+++ b/scripts/bgfx.lua
@@ -65,7 +65,7 @@ function bgfxProjectBase(_kind, _defines)
}
links {
"X11",
- "GL",
+ "EGL",
"pthread",
}
diff --git a/scripts/genie.lua b/scripts/genie.lua
index 2f4682e50..1ef9b7ca6 100644
--- a/scripts/genie.lua
+++ b/scripts/genie.lua
@@ -393,7 +393,7 @@ function exampleProjectDefaults()
configuration { "linux-* or freebsd" }
links {
"X11",
- "GL",
+ "EGL",
"pthread",
}
diff --git a/scripts/geometryv.lua b/scripts/geometryv.lua
index e403d5821..a635daabd 100644
--- a/scripts/geometryv.lua
+++ b/scripts/geometryv.lua
@@ -129,7 +129,7 @@ project ("geometryv")
configuration { "linux-* or freebsd" }
links {
"X11",
- "GL",
+ "EGL",
"pthread",
}
diff --git a/scripts/texturev.lua b/scripts/texturev.lua
index d5bb9e2f0..2aed5ecbc 100644
--- a/scripts/texturev.lua
+++ b/scripts/texturev.lua
@@ -129,7 +129,7 @@ project ("texturev")
configuration { "linux-* or freebsd" }
links {
"X11",
- "GL",
+ "EGL",
"pthread",
}
diff --git a/src/renderer_gl.h b/src/renderer_gl.h
index d9f7fbbe6..91c85e5b5 100644
--- a/src/renderer_gl.h
+++ b/src/renderer_gl.h
@@ -6,14 +6,17 @@
#ifndef BGFX_RENDERER_GL_H_HEADER_GUARD
#define BGFX_RENDERER_GL_H_HEADER_GUARD
-#define BGFX_USE_EGL (BGFX_CONFIG_RENDERER_OPENGLES && (0 \
+#define BGFX_USE_EGL ((BGFX_CONFIG_RENDERER_OPENGLES && (0 \
|| BX_PLATFORM_ANDROID \
|| BX_PLATFORM_BSD \
|| BX_PLATFORM_LINUX \
|| BX_PLATFORM_NX \
|| BX_PLATFORM_RPI \
|| BX_PLATFORM_WINDOWS \
- ) )
+ ) ) \
+ || (BGFX_CONFIG_RENDERER_OPENGL && (0 \
+ || BX_PLATFORM_LINUX \
+ ) ) )
#define BGFX_USE_HTML5 (BGFX_CONFIG_RENDERER_OPENGLES && (0 \
|| BX_PLATFORM_EMSCRIPTEN \
@@ -25,7 +28,6 @@
#define BGFX_USE_GLX (BGFX_CONFIG_RENDERER_OPENGL && (0 \
|| BX_PLATFORM_BSD \
- || BX_PLATFORM_LINUX \
) )
#define BGFX_USE_GL_DYNAMIC_LIB (0 \
@@ -76,6 +78,7 @@
# define GL_PROTOTYPES
# define GL_GLEXT_LEGACY
# include <GL/gl.h>
+# include "glcontext_egl.h"
# undef GL_PROTOTYPES
# elif BX_PLATFORM_OSX
# define GL_GLEXT_LEGACY Unfortunately, this has not helped getting running under wayland to work:
|
Here is the current backtrace with wayland backend, it seems to have changed since the first comment:
|
When using SDL, you check the |
As you can see in the SDL issues above, I'm trying to get MAME+BGFX+Wayland working. So since there are probably multiple issues it makes more sense to make sure BGFX is actually able to work natively on Wayland. I don't mind spending a bit of time getting this working, just a couple of questions: Would it be acceptable to deprecate GLX support and use EGL only by default? My current WIP changeset introduces a --with-glx option to make inclusion of GLX support require manual configuration. I'm going to try to get EGL working for both OpenGL and GLES. I don't see the benefit of being able to support GLX+EGL in the same build for X11. In the above SDL issues I was told BGFX aliases the WAYLAND_DISPLAY to an X11 DISPLAY type, is this correct? Where in the code is this happening? I've not spotted it yet. Is as suggested the root of my failure to get MAME+BGFX+Wayland working? I was also told that MAME supplying the egl_window handle to BGFX via glcontext_egl.cpp is wrong, because it might be a vulkan backend which will need a Vulkan surface. Wouldn't it just be a different code path for using the Vulkan backend from within MAME which shouldn't be dealing with EGL surfaces at all? Any help appreciated! |
The EGL backend accepts a NativeWindow (X11 / Wayland window), from which it creates an EGLWindow. So passing an EGLWindow directly won't work indeed. |
I just checked with the latest upstream (after GLX was replaced with EGL) and there is good news: examples no longer crash with GL renderer, and a wayland window is created. Thank you @issam3105 and @goodartistscopy, great work! |
There is crash on exit, due switch to EGL, but might be EGL/driver issue. On render thread exit:
|
I do not see this on Fedora 38, neither with nvidia binary driver nor on mesa/amd:
|
@belegdol You're running examples? Exit sequence should have following:
Yours doesn't have:
Which implies that you're running something different (GLFW, or your own?). |
I am running linux-debug64 examples compiled with |
Try without |
This might be issue where EGL has to run on OS created thread. |
Without
With
|
Same on nvidia-535.54.03 driver. Vulkan default:
OpenGL renderer:
|
Below is the current backtrace with vulkan. Looking at the error:
|
Remaining issues fixed by #3143. |
Describe the bug
Examples built with SDL and wayland enabled segfault on an attempt to run with SDL_VIDEODRIVER=wayland.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Examples run and xeyes do not move when cursor is hovered over the examples window, indicating native wayland window is open
Additional context
This is on Fedora 33 x86_64 on an Asus UM425IA laptop, Ryzen 5 4500U APU.
Not specifying the SDL_VIDEODRIVER results in a different error:
The text was updated successfully, but these errors were encountered: