From e7838a8b9e775414d84bdb658ebee1b5e60220f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 2 May 2020 23:48:52 +0200 Subject: [PATCH] Platform: check before calling SDL_DestroyWindow(). Can cause a crash when exiting from constructor on Windows (but not on Linux). To be safe do the same for all others. --- src/Magnum/Platform/Sdl2Application.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Magnum/Platform/Sdl2Application.cpp b/src/Magnum/Platform/Sdl2Application.cpp index e65b5aa2b..f6cbe0d85 100644 --- a/src/Magnum/Platform/Sdl2Application.cpp +++ b/src/Magnum/Platform/Sdl2Application.cpp @@ -771,13 +771,18 @@ bool Sdl2Application::setSwapInterval(const Int interval) { void Sdl2Application::redraw() { _flags |= Flag::Redraw; } Sdl2Application::~Sdl2Application() { + /* SDL_DestroyWindow(_window) crashes on windows when _window is nullptr + (it doesn't seem to crash on Linux). Because this seems to be yet + another pointless platform difference, to be safe do the same check with + all. */ + #ifdef MAGNUM_TARGET_GL _context.reset(); #ifndef CORRADE_TARGET_EMSCRIPTEN - SDL_GL_DeleteContext(_glContext); + if(_glContext) SDL_GL_DeleteContext(_glContext); #else - SDL_FreeSurface(_surface); + if(_surface) SDL_FreeSurface(_surface); #endif #endif @@ -787,7 +792,7 @@ Sdl2Application::~Sdl2Application() { #endif #ifndef CORRADE_TARGET_EMSCRIPTEN - SDL_DestroyWindow(_window); + if(_window) SDL_DestroyWindow(_window); #endif SDL_Quit(); }