From eb8785a20990a7b35e82fcfcbe4d3c046fabe8c5 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 2 Apr 2024 21:25:32 +0200 Subject: [PATCH] Fix segfault if SDL GL context fails --- irr/src/CIrrDeviceSDL.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/irr/src/CIrrDeviceSDL.cpp b/irr/src/CIrrDeviceSDL.cpp index 17dc033d4..2609058a6 100644 --- a/irr/src/CIrrDeviceSDL.cpp +++ b/irr/src/CIrrDeviceSDL.cpp @@ -321,19 +321,21 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters ¶m) : //! destructor CIrrDeviceSDL::~CIrrDeviceSDL() { - if (--SDLDeviceInstances == 0) { #if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) - const u32 numJoysticks = Joysticks.size(); - for (u32 i = 0; i < numJoysticks; ++i) - SDL_JoystickClose(Joysticks[i]); + const u32 numJoysticks = Joysticks.size(); + for (u32 i = 0; i < numJoysticks; ++i) + SDL_JoystickClose(Joysticks[i]); #endif - if (Window) { - SDL_GL_MakeCurrent(Window, NULL); - SDL_GL_DeleteContext(Context); - SDL_DestroyWindow(Window); - } - SDL_Quit(); + if (Window && Context) { + SDL_GL_MakeCurrent(Window, NULL); + SDL_GL_DeleteContext(Context); + } + if (Window) { + SDL_DestroyWindow(Window); + } + if (--SDLDeviceInstances == 0) { + SDL_Quit(); os::Printer::log("Quit SDL", ELL_INFORMATION); } }