diff --git a/src/window.c b/src/window.c index 83f8728f..0e264f5f 100644 --- a/src/window.c +++ b/src/window.c @@ -327,17 +327,8 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, return NULL; } - window = (_GLFWwindow*) _glfwMalloc(sizeof(_GLFWwindow)); - if (!window) - { - _glfwSetError(GLFW_OUT_OF_MEMORY, "glfwOpenWindow: Failed to allocate window structure"); - return NULL; - } - - memset(window, 0, sizeof(_GLFWwindow)); - - window->next = _glfwLibrary.windowListHead; - _glfwLibrary.windowListHead = window; + // We need to copy these values before doing anything that can fail, as the + // window hints should be cleared after each call even if it fails // Set up desired framebuffer config fbconfig.redBits = Max(_glfwLibrary.hints.redBits, 0); @@ -371,14 +362,10 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, // Check the OpenGL bits of the window config if (!isValidContextConfig(&wndconfig)) - { - glfwCloseWindow(window); return GL_FALSE; - } if (mode != GLFW_WINDOWED && mode != GLFW_FULLSCREEN) { - glfwCloseWindow(window); _glfwSetError(GLFW_INVALID_ENUM, "glfwOpenWindow: Invalid enum for 'mode' parameter"); return GL_FALSE; } @@ -401,6 +388,18 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, height = 480; } + window = (_GLFWwindow*) _glfwMalloc(sizeof(_GLFWwindow)); + if (!window) + { + _glfwSetError(GLFW_OUT_OF_MEMORY, "glfwOpenWindow: Failed to allocate window structure"); + return NULL; + } + + memset(window, 0, sizeof(_GLFWwindow)); + + window->next = _glfwLibrary.windowListHead; + _glfwLibrary.windowListHead = window; + // Remember window settings window->width = width; window->height = height;