Fix segfault if SDL GL context fails

This commit is contained in:
sfan5 2024-04-02 21:25:32 +02:00
parent d4b10db998
commit eb8785a209

@ -321,19 +321,21 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters &param) :
//! destructor //! destructor
CIrrDeviceSDL::~CIrrDeviceSDL() CIrrDeviceSDL::~CIrrDeviceSDL()
{ {
if (--SDLDeviceInstances == 0) {
#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) #if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)
const u32 numJoysticks = Joysticks.size(); const u32 numJoysticks = Joysticks.size();
for (u32 i = 0; i < numJoysticks; ++i) for (u32 i = 0; i < numJoysticks; ++i)
SDL_JoystickClose(Joysticks[i]); SDL_JoystickClose(Joysticks[i]);
#endif #endif
if (Window) { if (Window && Context) {
SDL_GL_MakeCurrent(Window, NULL); SDL_GL_MakeCurrent(Window, NULL);
SDL_GL_DeleteContext(Context); SDL_GL_DeleteContext(Context);
SDL_DestroyWindow(Window); }
} if (Window) {
SDL_Quit(); SDL_DestroyWindow(Window);
}
if (--SDLDeviceInstances == 0) {
SDL_Quit();
os::Printer::log("Quit SDL", ELL_INFORMATION); os::Printer::log("Quit SDL", ELL_INFORMATION);
} }
} }