Move the fix for Bugzilla #1395 into WIN_GL_SetupWindow() directly.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 01 Aug 2013 00:27:22 -0400
changeset 7559 0dd3b05797f9
parent 7558 0614504d2265
child 7560 1d6717a8b256
Move the fix for Bugzilla #1395 into WIN_GL_SetupWindow() directly. It's a cleaner solution.
src/video/windows/SDL_windowsopengl.c
src/video/windows/SDL_windowswindow.c
--- a/src/video/windows/SDL_windowsopengl.c	Wed Jul 31 21:22:09 2013 -0700
+++ b/src/video/windows/SDL_windowsopengl.c	Thu Aug 01 00:27:22 2013 -0400
@@ -418,8 +418,9 @@
     return pixel_format;
 }
 
-int
-WIN_GL_SetupWindow(_THIS, SDL_Window * window)
+/* actual work of WIN_GL_SetupWindow() happens here. */
+static int
+WIN_GL_SetupWindowInternal(_THIS, SDL_Window * window)
 {
     HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
     PIXELFORMATDESCRIPTOR pfd;
@@ -529,6 +530,17 @@
     return 0;
 }
 
+int
+WIN_GL_SetupWindow(_THIS, SDL_Window * window)
+{
+    /* The current context is lost in here; save it and reset it. */
+    SDL_Window *current_win = SDL_GL_GetCurrentWindow();
+    SDL_GLContext current_ctx = SDL_GL_GetCurrentContext();
+    const int retval = WIN_GL_SetupWindowInternal(_this, window);
+    WIN_GL_MakeCurrent(_this, current_win, current_ctx);
+    return retval;
+}
+
 SDL_GLContext
 WIN_GL_CreateContext(_THIS, SDL_Window * window)
 {
--- a/src/video/windows/SDL_windowswindow.c	Wed Jul 31 21:22:09 2013 -0700
+++ b/src/video/windows/SDL_windowswindow.c	Thu Aug 01 00:27:22 2013 -0400
@@ -231,15 +231,10 @@
     }
 #if SDL_VIDEO_OPENGL_WGL
     if (window->flags & SDL_WINDOW_OPENGL) {
-        /* The current context is lost in SDL_GL_SetupWindow; recover it. */
-        SDL_Window *current_win = SDL_GL_GetCurrentWindow();
-        SDL_GLContext current_ctx = SDL_GL_GetCurrentContext();
         if (WIN_GL_SetupWindow(_this, window) < 0) {
             WIN_DestroyWindow(_this, window);
-            WIN_GL_MakeCurrent(_this, current_win, current_ctx);
             return -1;
         }
-        WIN_GL_MakeCurrent(_this, current_win, current_ctx);
     }
 #endif
     return 0;