From 467d5016210cc8f13b6bde7812df7ea773a3dd79 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 21 Oct 2012 21:57:29 +0200 Subject: [PATCH] Cleanup of context clearing during window destruction. --- src/cocoa_window.m | 3 --- src/win32_opengl.c | 5 ----- src/win32_window.c | 8 ++++++++ src/window.c | 4 ++-- src/x11_opengl.c | 2 -- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index c01582c1..fd60d0ee 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -969,9 +969,6 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window) [window->NSGL.pixelFormat release]; window->NSGL.pixelFormat = nil; - if ([NSOpenGLContext currentContext] == window->NSGL.context) - [NSOpenGLContext clearCurrentContext]; - [window->NSGL.context release]; window->NSGL.context = nil; diff --git a/src/win32_opengl.c b/src/win32_opengl.c index c326dac7..acbf09f5 100644 --- a/src/win32_opengl.c +++ b/src/win32_opengl.c @@ -528,11 +528,6 @@ int _glfwCreateContext(_GLFWwindow* window, void _glfwDestroyContext(_GLFWwindow* window) { - // This is duplicated from glfwDestroyWindow - // TODO: Stop duplicating code - if (window == _glfwCurrentWindow) - _glfwPlatformMakeContextCurrent(NULL); - if (window->WGL.context) { wglDeleteContext(window->WGL.context); diff --git a/src/win32_window.c b/src/win32_window.c index 6b275476..6bb9509d 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -947,8 +947,16 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, // we're just creating an OpenGL 3.0+ context with the same pixel // format, but it's not worth the added code complexity + // First we clear the current context (the one we just created) + // This is usually done by glfwDestroyWindow, but as we're not doing + // full window destruction, it's duplicated here + _glfwPlatformMakeContextCurrent(NULL); + + // Next destroy the Win32 window and WGL context (without resetting or + // destroying the GLFW window object) destroyWindow(window); + // ...and then create them again, this time with better APIs if (!createWindow(window, wndconfig, fbconfig)) return GL_FALSE; } diff --git a/src/window.c b/src/window.c index 741938d1..bb1093f5 100644 --- a/src/window.c +++ b/src/window.c @@ -483,8 +483,8 @@ GLFWAPI void glfwDestroyWindow(GLFWwindow handle) if (window == NULL) return; - // Clear the current context if this window's context is current - // TODO: Re-examine this in light of multithreading + // The window's context must not be current on another thread when the + // window is destroyed if (window == _glfwPlatformGetCurrentContext()) _glfwPlatformMakeContextCurrent(NULL); diff --git a/src/x11_opengl.c b/src/x11_opengl.c index 19e04a4f..ccd59d87 100644 --- a/src/x11_opengl.c +++ b/src/x11_opengl.c @@ -619,8 +619,6 @@ void _glfwDestroyContext(_GLFWwindow* window) if (window->GLX.context) { - // Release and destroy the context - glXMakeCurrent(_glfwLibrary.X11.display, None, NULL); glXDestroyContext(_glfwLibrary.X11.display, window->GLX.context); window->GLX.context = NULL; }