diff --git a/src/x11_opengl.c b/src/x11_opengl.c index 5ec47ee5..35dc6d0f 100644 --- a/src/x11_opengl.c +++ b/src/x11_opengl.c @@ -637,6 +637,12 @@ int _glfwCreateContext(_GLFWwindow* window, void _glfwDestroyContext(_GLFWwindow* window) { + if (window->GLX.visual) + { + XFree(window->GLX.visual); + window->GLX.visual = NULL; + } + if (window->GLX.context) { // Release and destroy the context @@ -647,6 +653,16 @@ void _glfwDestroyContext(_GLFWwindow* window) } +//======================================================================== +// Return the X visual associated with the specified context +//======================================================================== + +XVisualInfo* _glfwGetContextVisual(_GLFWwindow* window) +{ + return window->GLX.visual; +} + + //======================================================================== // Make the OpenGL context associated with the specified window current //======================================================================== diff --git a/src/x11_platform.h b/src/x11_platform.h index d45ad9a3..4d432f80 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -289,6 +289,7 @@ int _glfwCreateContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWfbconfig* fbconfig); void _glfwDestroyContext(_GLFWwindow* window); +XVisualInfo* _glfwGetContextVisual(_GLFWwindow* window); // Fullscreen support int _glfwGetClosestVideoMode(int* width, int* height, int* rate); diff --git a/src/x11_window.c b/src/x11_window.c index a5e7b0d8..9ec54493 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -97,13 +97,14 @@ static GLboolean createWindow(_GLFWwindow* window, XEvent event; unsigned long wamask; XSetWindowAttributes wa; + XVisualInfo* visual = _glfwGetContextVisual(window); // Every window needs a colormap // Create one based on the visual used by the current context window->X11.colormap = XCreateColormap(_glfwLibrary.X11.display, _glfwLibrary.X11.root, - window->GLX.visual->visual, + visual->visual, AllocNone); // Create the actual window @@ -133,9 +134,9 @@ static GLboolean createWindow(_GLFWwindow* window, 0, 0, // Upper left corner of this window on root window->width, window->height, 0, // Border width - window->GLX.visual->depth, // Color depth + visual->depth, // Color depth InputOutput, - window->GLX.visual->visual, + visual->visual, wamask, &wa ); @@ -979,12 +980,6 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window) _glfwDestroyContext(window); - if (window->GLX.visual) - { - XFree(window->GLX.visual); - window->GLX.visual = NULL; - } - if (window->X11.handle) { XUnmapWindow(_glfwLibrary.X11.display, window->X11.handle);