include/ui/egl-helpers.h | 5 +++++ ui/egl-helpers.c | 4 ++-- ui/sdl2.c | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-)
Mesa's eglGetDisplay() chooses the native EGL platform from
EGL_PLATFORM, limited autodetection, or the build-time default. If that
selects Wayland while SDL is using the X11 video backend, Mesa can treat
the X11 Display pointer as a wl_display and crash during eglInitialize().
Probe EGL with the X11 platform explicitly before enabling
SDL_HINT_VIDEO_X11_FORCE_EGL.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3540
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
---
Resolving the issue described in the GitLab work item also requires:
https://github.com/libsdl-org/SDL/pull/15806
---
include/ui/egl-helpers.h | 5 +++++
ui/egl-helpers.c | 4 ++--
ui/sdl2.c | 3 ++-
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/include/ui/egl-helpers.h b/include/ui/egl-helpers.h
index acf993fcf52f..c97a0d5c248f 100644
--- a/include/ui/egl-helpers.h
+++ b/include/ui/egl-helpers.h
@@ -61,6 +61,11 @@ void egl_dmabuf_create_fence(QemuDmaBuf *dmabuf);
EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, EGLNativeWindowType win);
+#if defined(CONFIG_X11) || defined(CONFIG_GBM) || defined(WIN32)
+EGLDisplay qemu_egl_get_display(EGLNativeDisplayType native,
+ EGLenum platform);
+#endif
+
#if defined(CONFIG_X11) || defined(CONFIG_GBM)
int qemu_egl_init_dpy_x11(EGLNativeDisplayType dpy, DisplayGLMode mode);
diff --git a/ui/egl-helpers.c b/ui/egl-helpers.c
index e3f2872cc14b..069a52495541 100644
--- a/ui/egl-helpers.c
+++ b/ui/egl-helpers.c
@@ -520,8 +520,8 @@ EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, EGLNativeWindowType win)
* platform extensions (EGL_KHR_platform_gbm and friends) yet it doesn't seem
* like mesa will be able to advertise these (even though it can do EGL 1.5).
*/
-static EGLDisplay qemu_egl_get_display(EGLNativeDisplayType native,
- EGLenum platform)
+EGLDisplay qemu_egl_get_display(EGLNativeDisplayType native,
+ EGLenum platform)
{
EGLDisplay dpy = EGL_NO_DISPLAY;
diff --git a/ui/sdl2.c b/ui/sdl2.c
index 4fcdbd79d3c0..ce14bd1f4e15 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -862,7 +862,8 @@ static void sdl2_set_hint_x11_force_egl(void)
}
/* Prefer EGL over GLX to get dma-buf support. */
- egl_display = eglGetDisplay((EGLNativeDisplayType)x_disp);
+ egl_display = qemu_egl_get_display((EGLNativeDisplayType)x_disp,
+ EGL_PLATFORM_X11_KHR);
if (egl_display != EGL_NO_DISPLAY) {
/*
---
base-commit: 2db91528542672cf0db78b3f2cc0e22b36302b38
change-id: 20260611-sdl-a148cd469727
Best regards,
--
Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
On 11.06.2026 14:58, Akihiko Odaki wrote: > Mesa's eglGetDisplay() chooses the native EGL platform from > EGL_PLATFORM, limited autodetection, or the build-time default. If that > selects Wayland while SDL is using the X11 video backend, Mesa can treat > the X11 Display pointer as a wl_display and crash during eglInitialize(). > > Probe EGL with the X11 platform explicitly before enabling > SDL_HINT_VIDEO_X11_FORCE_EGL. > > Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3540 > Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> > --- > Resolving the issue described in the GitLab work item also requires: > https://github.com/libsdl-org/SDL/pull/15806 This looks like a qemu-stable material (11.0.x only?). I'm picking this up for qemu 11.0.x series. Please let me know if I shouldn't. > include/ui/egl-helpers.h | 5 +++++ > ui/egl-helpers.c | 4 ++-- > ui/sdl2.c | 3 ++- > 3 files changed, 9 insertions(+), 3 deletions(-) Thanks, /mjt
On Thu, 11 Jun 2026 at 13:58, Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> wrote: > Resolving the issue described in the GitLab work item also requires: > https://github.com/libsdl-org/SDL/pull/15806 Thanks! The pull request is only towards SDL2. I believe SDL3 (via sdl2 compat layer) isn't affected (it sets the platform correctly in my testing). Is that right? Alex
On 2026/06/11 23:44, Alexander Kanavin wrote: > On Thu, 11 Jun 2026 at 13:58, Akihiko Odaki > <odaki@rsg.ci.i.u-tokyo.ac.jp> wrote: >> Resolving the issue described in the GitLab work item also requires: >> https://github.com/libsdl-org/SDL/pull/15806 > > Thanks! The pull request is only towards SDL2. I believe SDL3 (via > sdl2 compat layer) isn't affected (it sets the platform correctly in > my testing). Is that right? Upstream developers are working on a fix: https://github.com/libsdl-org/SDL/pull/15809 Regards, Akihiko Odaki
On Thu, Jun 11, 2026 at 4:00 PM Akihiko Odaki
<odaki@rsg.ci.i.u-tokyo.ac.jp> wrote:
>
> Mesa's eglGetDisplay() chooses the native EGL platform from
> EGL_PLATFORM, limited autodetection, or the build-time default. If that
> selects Wayland while SDL is using the X11 video backend, Mesa can treat
> the X11 Display pointer as a wl_display and crash during eglInitialize().
>
> Probe EGL with the X11 platform explicitly before enabling
> SDL_HINT_VIDEO_X11_FORCE_EGL.
>
> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3540
> Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> Resolving the issue described in the GitLab work item also requires:
> https://github.com/libsdl-org/SDL/pull/15806
> ---
> include/ui/egl-helpers.h | 5 +++++
> ui/egl-helpers.c | 4 ++--
> ui/sdl2.c | 3 ++-
> 3 files changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/include/ui/egl-helpers.h b/include/ui/egl-helpers.h
> index acf993fcf52f..c97a0d5c248f 100644
> --- a/include/ui/egl-helpers.h
> +++ b/include/ui/egl-helpers.h
> @@ -61,6 +61,11 @@ void egl_dmabuf_create_fence(QemuDmaBuf *dmabuf);
>
> EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, EGLNativeWindowType win);
>
> +#if defined(CONFIG_X11) || defined(CONFIG_GBM) || defined(WIN32)
> +EGLDisplay qemu_egl_get_display(EGLNativeDisplayType native,
> + EGLenum platform);
> +#endif
> +
> #if defined(CONFIG_X11) || defined(CONFIG_GBM)
>
> int qemu_egl_init_dpy_x11(EGLNativeDisplayType dpy, DisplayGLMode mode);
> diff --git a/ui/egl-helpers.c b/ui/egl-helpers.c
> index e3f2872cc14b..069a52495541 100644
> --- a/ui/egl-helpers.c
> +++ b/ui/egl-helpers.c
> @@ -520,8 +520,8 @@ EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, EGLNativeWindowType win)
> * platform extensions (EGL_KHR_platform_gbm and friends) yet it doesn't seem
> * like mesa will be able to advertise these (even though it can do EGL 1.5).
> */
> -static EGLDisplay qemu_egl_get_display(EGLNativeDisplayType native,
> - EGLenum platform)
> +EGLDisplay qemu_egl_get_display(EGLNativeDisplayType native,
> + EGLenum platform)
> {
> EGLDisplay dpy = EGL_NO_DISPLAY;
>
> diff --git a/ui/sdl2.c b/ui/sdl2.c
> index 4fcdbd79d3c0..ce14bd1f4e15 100644
> --- a/ui/sdl2.c
> +++ b/ui/sdl2.c
> @@ -862,7 +862,8 @@ static void sdl2_set_hint_x11_force_egl(void)
> }
>
> /* Prefer EGL over GLX to get dma-buf support. */
> - egl_display = eglGetDisplay((EGLNativeDisplayType)x_disp);
> + egl_display = qemu_egl_get_display((EGLNativeDisplayType)x_disp,
> + EGL_PLATFORM_X11_KHR);
>
> if (egl_display != EGL_NO_DISPLAY) {
> /*
>
> ---
> base-commit: 2db91528542672cf0db78b3f2cc0e22b36302b38
> change-id: 20260611-sdl-a148cd469727
>
> Best regards,
> --
> Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
>
>
© 2016 - 2026 Red Hat, Inc.