diff --git a/src/posix/sdl/sdlglvideo.cpp b/src/posix/sdl/sdlglvideo.cpp index 47580f830..78f545216 100644 --- a/src/posix/sdl/sdlglvideo.cpp +++ b/src/posix/sdl/sdlglvideo.cpp @@ -145,6 +145,14 @@ namespace Priv } } + void DestroyWindow() + { + assert(Priv::window != nullptr); + + SDL_DestroyWindow(Priv::window); + Priv::window = nullptr; + } + void SetupPixelFormat(int multisample, const int *glver) { SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); @@ -276,6 +284,11 @@ DFrameBuffer *SDLVideo::CreateFrameBuffer () } catch (CRecoverableError const&) { + if (Priv::window != nullptr) + { + Priv::DestroyWindow(); + } + Priv::vulkanEnabled = false; } } @@ -428,8 +441,7 @@ SystemGLFrameBuffer::SystemGLFrameBuffer(void *hMonitor, bool fullscreen) GLContext = SDL_GL_CreateContext(Priv::window); if (GLContext == nullptr) { - SDL_DestroyWindow(Priv::window); - Priv::window = nullptr; + Priv::DestroyWindow(); } else { @@ -447,8 +459,7 @@ SystemGLFrameBuffer::~SystemGLFrameBuffer () SDL_GL_DeleteContext(GLContext); } - SDL_DestroyWindow(Priv::window); - Priv::window = nullptr; + Priv::DestroyWindow(); } }