mirror of
https://github.com/glfw/glfw.git
synced 2024-11-26 20:11:58 +00:00
Delayed window struct allocation.
This commit is contained in:
parent
98eb79b7d9
commit
d1d550d1ab
29
src/window.c
29
src/window.c
@ -327,17 +327,8 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
window = (_GLFWwindow*) _glfwMalloc(sizeof(_GLFWwindow));
|
// We need to copy these values before doing anything that can fail, as the
|
||||||
if (!window)
|
// window hints should be cleared after each call even if it fails
|
||||||
{
|
|
||||||
_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;
|
|
||||||
|
|
||||||
// Set up desired framebuffer config
|
// Set up desired framebuffer config
|
||||||
fbconfig.redBits = Max(_glfwLibrary.hints.redBits, 0);
|
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
|
// Check the OpenGL bits of the window config
|
||||||
if (!isValidContextConfig(&wndconfig))
|
if (!isValidContextConfig(&wndconfig))
|
||||||
{
|
|
||||||
glfwCloseWindow(window);
|
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
|
||||||
|
|
||||||
if (mode != GLFW_WINDOWED && mode != GLFW_FULLSCREEN)
|
if (mode != GLFW_WINDOWED && mode != GLFW_FULLSCREEN)
|
||||||
{
|
{
|
||||||
glfwCloseWindow(window);
|
|
||||||
_glfwSetError(GLFW_INVALID_ENUM, "glfwOpenWindow: Invalid enum for 'mode' parameter");
|
_glfwSetError(GLFW_INVALID_ENUM, "glfwOpenWindow: Invalid enum for 'mode' parameter");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
@ -401,6 +388,18 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
|
|||||||
height = 480;
|
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
|
// Remember window settings
|
||||||
window->width = width;
|
window->width = width;
|
||||||
window->height = height;
|
window->height = height;
|
||||||
|
Loading…
Reference in New Issue
Block a user