From 926d2beddba15baea57c21b7ab905f4884e1827a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 6 Feb 2017 15:58:15 +0100 Subject: [PATCH] Move initialized flag into library struct --- src/init.c | 14 +++++--------- src/internal.h | 14 +++++--------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/init.c b/src/init.c index 7d60d133..85148379 100644 --- a/src/init.c +++ b/src/init.c @@ -33,14 +33,12 @@ #include -// The three global variables below comprise all global data in GLFW. +// The global variables below comprise all global data in GLFW. // Any other global variable is a bug. // Global state shared between compilation units of GLFW -// These are documented in internal.h // -GLFWbool _glfwInitialized = GLFW_FALSE; -_GLFWlibrary _glfw; +_GLFWlibrary _glfw = { GLFW_FALSE }; // This is outside of _glfw so it can be initialized and usable before // glfwInit is called, which lets that function report errors @@ -119,7 +117,7 @@ void _glfwInputError(int error, const char* format, ...) GLFWAPI int glfwInit(void) { - if (_glfwInitialized) + if (_glfw.initialized) return GLFW_TRUE; memset(&_glfw, 0, sizeof(_glfw)); @@ -130,8 +128,7 @@ GLFWAPI int glfwInit(void) return GLFW_FALSE; } - _glfwInitialized = GLFW_TRUE; - + _glfw.initialized = GLFW_TRUE; _glfw.timerOffset = _glfwPlatformGetTimerValue(); // Not all window hints have zero as their default value @@ -144,7 +141,7 @@ GLFWAPI void glfwTerminate(void) { int i; - if (!_glfwInitialized) + if (!_glfw.initialized) return; memset(&_glfw.callbacks, 0, sizeof(_glfw.callbacks)); @@ -171,7 +168,6 @@ GLFWAPI void glfwTerminate(void) _glfwPlatformTerminate(); memset(&_glfw, 0, sizeof(_glfw)); - _glfwInitialized = GLFW_FALSE; } GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev) diff --git a/src/internal.h b/src/internal.h index e1bab46b..e71ac171 100644 --- a/src/internal.h +++ b/src/internal.h @@ -230,13 +230,13 @@ typedef void (APIENTRY * PFN_vkVoidFunction)(void); // Checks for whether the library has been initialized #define _GLFW_REQUIRE_INIT() \ - if (!_glfwInitialized) \ + if (!_glfw.initialized) \ { \ _glfwInputError(GLFW_NOT_INITIALIZED, NULL); \ return; \ } #define _GLFW_REQUIRE_INIT_OR_RETURN(x) \ - if (!_glfwInitialized) \ + if (!_glfw.initialized) \ { \ _glfwInputError(GLFW_NOT_INITIALIZED, NULL); \ return x; \ @@ -468,6 +468,8 @@ struct _GLFWjoystick */ struct _GLFWlibrary { + GLFWbool initialized; + struct { _GLFWfbconfig framebuffer; _GLFWwndconfig window; @@ -533,13 +535,7 @@ struct _GLFWlibrary // Global state shared between compilation units of GLFW //======================================================================== -/*! @brief Flag indicating whether GLFW has been successfully initialized. - */ -extern GLFWbool _glfwInitialized; - -/*! @brief All global data protected by @ref _glfwInitialized. - * This should only be touched after a call to @ref glfwInit that has not been - * followed by a call to @ref glfwTerminate. +/*! @brief All global data shared between compilation units. */ extern _GLFWlibrary _glfw;