Skip to content

Commit

Permalink
Fix segfault if SDL GL context fails
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Apr 3, 2024
1 parent d4b10db commit eb8785a
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions irr/src/CIrrDeviceSDL.cpp
Expand Up @@ -321,19 +321,21 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters &param) :
//! 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);
}
}
Expand Down

0 comments on commit eb8785a

Please sign in to comment.