Allow error callback to be set before glfwInit.

This commit is contained in:
Camilla Berglund 2011-09-16 01:16:31 +02:00
parent 58db28ea83
commit d0af26cd43
3 changed files with 11 additions and 21 deletions

View File

@ -35,10 +35,13 @@
//////////////////////////////////////////////////////////////////////////
//========================================================================
// The current error value
// The current error value and callback
// These are not in _glfwLibrary since they need to be initialized and
// accessible before glfwInit
//========================================================================
static int _glfwError = GLFW_NO_ERROR;
static GLFWerrorfun _glfwErrorCallback = NULL;
//========================================================================
@ -48,18 +51,12 @@ static int _glfwError = GLFW_NO_ERROR;
void _glfwSetError(int error, const char* description)
{
if (!_glfwInitialized)
{
_glfwError = error;
return;
}
if (_glfwLibrary.errorCallback)
if (_glfwErrorCallback)
{
if (!description)
description = glfwErrorString(error);
_glfwLibrary.errorCallback(error, description);
_glfwErrorCallback(error, description);
}
else
_glfwError = error;
@ -110,9 +107,9 @@ GLFWAPI const char* glfwErrorString(int error)
return "The requested OpenGL version is unavailable";
case GLFW_PLATFORM_ERROR:
return "A platform-specific error occurred";
default:
return "ERROR: UNKNOWN ERROR TOKEN PASSED TO glfwErrorString";
}
return "ERROR: UNKNOWN ERROR TOKEN PASSED TO glfwErrorString";
}
@ -122,12 +119,6 @@ GLFWAPI const char* glfwErrorString(int error)
GLFWAPI void glfwSetErrorCallback(GLFWerrorfun cbfun)
{
if (!_glfwInitialized)
{
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_glfwLibrary.errorCallback = cbfun;
_glfwErrorCallback = cbfun;
}

View File

@ -226,7 +226,6 @@ struct _GLFWlibrary
_GLFWwindow* currentWindow;
_GLFWwindow* activeWindow;
GLFWerrorfun errorCallback;
GLFWwindowsizefun windowSizeCallback;
GLFWwindowclosefun windowCloseCallback;
GLFWwindowrefreshfun windowRefreshCallback;

View File

@ -174,14 +174,14 @@ int main(int argc, char** argv)
argc -= optind;
argv += optind;
glfwSetErrorCallback(error_callback);
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
}
glfwSetErrorCallback(error_callback);
if (major != 1 || minor != 0)
{
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, major);