Linux: SDL2 - Try to use X11 video driver first, the default on some systems (e.g Wayland on Fedora 42) causes the application to crash

This commit is contained in:
Sour 2025-06-13 10:59:19 +09:00
parent a17bb92dbb
commit 0cd2f38943

View File

@ -40,6 +40,8 @@ void SdlRenderer::SetExclusiveFullscreenMode(bool fullscreen, void* windowHandle
bool SdlRenderer::Init()
{
const char* originalHint = SDL_GetHint("SDL_VIDEODRIVER");
SDL_SetHint("SDL_VIDEODRIVER", "x11");
if(SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) {
LogSdlError("[SDL] Failed to initialize video subsystem.");
return false;
@ -47,10 +49,10 @@ bool SdlRenderer::Init()
_sdlWindow = SDL_CreateWindowFrom(_windowHandle);
if(!_sdlWindow) {
MessageManager::Log("[SDL] Failed to create window from handle, retry with SDL_VIDEODRIVER=x11...");
MessageManager::Log("[SDL] Failed to create window from handle with SDL_VIDEODRIVER=x11, retry with default...");
SDL_QuitSubSystem(SDL_INIT_VIDEO);
SDL_SetHint("SDL_VIDEODRIVER", "x11");
SDL_SetHint("SDL_VIDEODRIVER", originalHint);
if(SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) {
LogSdlError("[SDL] Failed to initialize video subsystem.");
return false;
@ -61,7 +63,7 @@ bool SdlRenderer::Init()
LogSdlError("[SDL] Failed to create window from handle.");
return false;
} else {
MessageManager::Log("[SDL] Window creation succeeded with SDL_VIDEODRIVER=x11");
MessageManager::Log("[SDL] Window creation succeeded with default driver.");
}
}