From adfd7362b5e753c89cff4ec195d720bee2f455b1 Mon Sep 17 00:00:00 2001 From: Yamagi Date: Sun, 31 Mar 2024 10:44:16 +0200 Subject: [PATCH] Explicitly shutdown the SDL_INIT_EVENTS subsystem. SDL_INIT_VIDEO includes SDL_INIT_EVENTS when initialized through SDL_Init(), but not when shutdown to SDL_Quit(). Handle the shutdown in the input subsystem. This closes some memory leaks in SDL. --- src/client/input/sdl3.c | 12 +++++++++++- src/client/vid/glimp_sdl3.c | 5 ----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/client/input/sdl3.c b/src/client/input/sdl3.c index 497450fa..ebbaf2ff 100644 --- a/src/client/input/sdl3.c +++ b/src/client/input/sdl3.c @@ -2310,6 +2310,14 @@ IN_Init(void) Cmd_AddCommand("+gyroaction", IN_GyroActionDown); Cmd_AddCommand("-gyroaction", IN_GyroActionUp); + if (!SDL_WasInit(SDL_INIT_EVENTS)) + { + if ((SDL_InitSubSystem(SDL_INIT_EVENTS)) != 0) + { + Com_Error(ERR_FATAL, "Couldn't initialize SDL event subsystem:%s\n", SDL_GetError()); + } + } + SDL_StartTextInput(); IN_Controller_Init(false); @@ -2379,9 +2387,11 @@ IN_Shutdown(void) IN_Controller_Shutdown(false); - const Uint32 subsystems = SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC; + const Uint32 subsystems = SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC | SDL_INIT_EVENTS; if (SDL_WasInit(subsystems) == subsystems) + { SDL_QuitSubSystem(subsystems); + } } /* ------------------------------------------------------------------ */ diff --git a/src/client/vid/glimp_sdl3.c b/src/client/vid/glimp_sdl3.c index 340d1f9d..8c5ab122 100644 --- a/src/client/vid/glimp_sdl3.c +++ b/src/client/vid/glimp_sdl3.c @@ -451,11 +451,6 @@ void GLimp_Shutdown(void) { ShutdownGraphics(); - - // TODO SDL3: SDL_INIT_VIDEO implies SDL_INIT_EVENTS - // in SDL 2 this was handled by SDL_INIT_EVERYTHING - // which is unavailable in SDL 3. Handle SDL_INIT_EVENTS - // in the input backend? SDL_QuitSubSystem(SDL_INIT_VIDEO); ClearDisplayIndices(); }