diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index ecf909568a..6e4d45f32b 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -3621,12 +3621,18 @@ void SDL_DestroyWindow(SDL_Window *window) } } - /* make no context current if this is the current context window. */ + /* Make no context current if this is the current context window */ if (window->flags & SDL_WINDOW_OPENGL) { if (_this->current_glwin == window) { SDL_GL_MakeCurrent(window, NULL); } } + + if (_this->DestroyWindow) { + _this->DestroyWindow(_this, window); + } + + /* Unload the graphics libraries after the window is destroyed, which may clean up EGL surfaces */ if (window->flags & SDL_WINDOW_OPENGL) { SDL_GL_UnloadLibrary(); } @@ -3634,10 +3640,6 @@ void SDL_DestroyWindow(SDL_Window *window) SDL_Vulkan_UnloadLibrary(); } - if (_this->DestroyWindow) { - _this->DestroyWindow(_this, window); - } - if (_this->grabbed_window == window) { _this->grabbed_window = NULL; /* ungrabbing input. */ }