From d1d550d1ab253ee155f0b702fa035bf84bfe5a91 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 7 Mar 2011 14:30:23 +0100 Subject: [PATCH] Delayed window struct allocation. --- src/window.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) 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;