From 2c9084d48cf1a3ad3c5f8d3bcad83c396e8d29fd Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Sat, 6 Feb 2021 14:09:45 +0100 Subject: [PATCH] Fix #8029: [SDL2] disable draw-thread on wayland SDL video driver (#8648) When the wayland SDL video driver is used, an EGL context is created in the main thread. It is not allowed to update this context from another thread, which is exactly what our draw-thread is trying. The other solution would be to move all of SDL into the draw-thread, but that would introduce a whole scala of different problems. The wayland SDL backend is significantly faster than the X11 SDL backend, but there is a performance hit nevertheless. --- src/video/sdl2_v.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/video/sdl2_v.cpp b/src/video/sdl2_v.cpp index 66e6586fdc..fd6cf6c112 100644 --- a/src/video/sdl2_v.cpp +++ b/src/video/sdl2_v.cpp @@ -715,6 +715,17 @@ const char *VideoDriver_SDL::Start(const StringList &parm) MarkWholeScreenDirty(); _draw_threaded = !GetDriverParamBool(parm, "no_threads") && !GetDriverParamBool(parm, "no_thread"); + /* Wayland SDL video driver uses EGL to render the game. SDL created the + * EGL context from the main-thread, and with EGL you are not allowed to + * draw in another thread than the context was created. The function of + * _draw_threaded is to do exactly this: draw in another thread than the + * window was created, and as such, this fails on Wayland SDL video + * driver. So, we disable threading by default if Wayland SDL video + * driver is detected. + */ + if (strcmp(dname, "wayland") == 0) { + _draw_threaded = false; + } SDL_StopTextInput(); this->edit_box_focused = false;