Browse Source

Don't unload graphics libraries until after the window has been destroyed.

This fixes creating a window after the first window has been destroyed on Android. The graphics library had been unloaded, so eglDestroySurface() wasn't called, leaving a surface attached to the window, which would prevent attaching new EGL surfaces to the window (eglCreateWindowSurface() would fail with BAD_ALLOC)
Sam Lantinga 1 year ago
parent
commit
b0e7b7db6f
1 changed files with 7 additions and 5 deletions
  1. 7 5
      src/video/SDL_video.c

+ 7 - 5
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. */
     }