Add glfwGetError

Related to #970.

If you have opinions on the design or implementation of this function,
please come join us in #970 before it is frozen for release.
This commit is contained in:
Camilla Löwy
2017-05-01 19:20:57 +02:00
parent 16ddfafeaa
commit 6350641f0a
8 changed files with 122 additions and 19 deletions
+35 -3
View File
@@ -43,6 +43,7 @@ _GLFWlibrary _glfw = { GLFW_FALSE };
// These are outside of _glfw so they can be used before initialization and
// after termination
//
static int _glfwErrorCode;
static GLFWerrorfun _glfwErrorCallback;
static _GLFWinitconfig _glfwInitHints =
{
@@ -113,7 +114,11 @@ static void terminate(void)
_glfwTerminateVulkan();
_glfwPlatformTerminate();
if (_glfwPlatformIsValidTls(&_glfw.error))
_glfwErrorCode = (int) (intptr_t) _glfwPlatformGetTls(&_glfw.error);
_glfwPlatformDestroyTls(&_glfw.context);
_glfwPlatformDestroyTls(&_glfw.error);
memset(&_glfw, 0, sizeof(_glfw));
}
@@ -125,6 +130,11 @@ static void terminate(void)
void _glfwInputError(int error, const char* format, ...)
{
if (_glfw.initialized)
_glfwPlatformSetTls(&_glfw.error, (void*) (intptr_t) error);
else
_glfwErrorCode = error;
if (_glfwErrorCallback)
{
char buffer[8192];
@@ -164,15 +174,19 @@ GLFWAPI int glfwInit(void)
memset(&_glfw, 0, sizeof(_glfw));
_glfw.hints.init = _glfwInitHints;
if (!_glfwPlatformCreateTls(&_glfw.context))
return GLFW_FALSE;
if (!_glfwPlatformInit())
{
terminate();
return GLFW_FALSE;
}
if (!_glfwPlatformCreateTls(&_glfw.error))
return GLFW_FALSE;
if (!_glfwPlatformCreateTls(&_glfw.context))
return GLFW_FALSE;
_glfwPlatformSetTls(&_glfw.error, (void*) (intptr_t) _glfwErrorCode);
_glfw.initialized = GLFW_TRUE;
_glfw.timer.offset = _glfwPlatformGetTimerValue();
@@ -223,6 +237,24 @@ GLFWAPI const char* glfwGetVersionString(void)
return _glfwPlatformGetVersionString();
}
GLFWAPI int glfwGetError(void)
{
int error;
if (_glfw.initialized)
{
error = (int) (intptr_t) _glfwPlatformGetTls(&_glfw.error);
_glfwPlatformSetTls(&_glfw.error, (intptr_t) GLFW_NO_ERROR);
}
else
{
error = _glfwErrorCode;
_glfwErrorCode = GLFW_NO_ERROR;
}
return error;
}
GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun)
{
_GLFW_SWAP_POINTERS(_glfwErrorCallback, cbfun);