Allow error callback to be set before glfwInit.
This commit is contained in:
parent
58db28ea83
commit
d0af26cd43
27
src/error.c
27
src/error.c
@ -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 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)
|
void _glfwSetError(int error, const char* description)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (_glfwErrorCallback)
|
||||||
{
|
|
||||||
_glfwError = error;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_glfwLibrary.errorCallback)
|
|
||||||
{
|
{
|
||||||
if (!description)
|
if (!description)
|
||||||
description = glfwErrorString(error);
|
description = glfwErrorString(error);
|
||||||
|
|
||||||
_glfwLibrary.errorCallback(error, description);
|
_glfwErrorCallback(error, description);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
_glfwError = error;
|
_glfwError = error;
|
||||||
@ -110,9 +107,9 @@ GLFWAPI const char* glfwErrorString(int error)
|
|||||||
return "The requested OpenGL version is unavailable";
|
return "The requested OpenGL version is unavailable";
|
||||||
case GLFW_PLATFORM_ERROR:
|
case GLFW_PLATFORM_ERROR:
|
||||||
return "A platform-specific error occurred";
|
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)
|
GLFWAPI void glfwSetErrorCallback(GLFWerrorfun cbfun)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
_glfwErrorCallback = cbfun;
|
||||||
{
|
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_glfwLibrary.errorCallback = cbfun;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,7 +226,6 @@ struct _GLFWlibrary
|
|||||||
_GLFWwindow* currentWindow;
|
_GLFWwindow* currentWindow;
|
||||||
_GLFWwindow* activeWindow;
|
_GLFWwindow* activeWindow;
|
||||||
|
|
||||||
GLFWerrorfun errorCallback;
|
|
||||||
GLFWwindowsizefun windowSizeCallback;
|
GLFWwindowsizefun windowSizeCallback;
|
||||||
GLFWwindowclosefun windowCloseCallback;
|
GLFWwindowclosefun windowCloseCallback;
|
||||||
GLFWwindowrefreshfun windowRefreshCallback;
|
GLFWwindowrefreshfun windowRefreshCallback;
|
||||||
|
@ -174,14 +174,14 @@ int main(int argc, char** argv)
|
|||||||
argc -= optind;
|
argc -= optind;
|
||||||
argv += optind;
|
argv += optind;
|
||||||
|
|
||||||
|
glfwSetErrorCallback(error_callback);
|
||||||
|
|
||||||
if (!glfwInit())
|
if (!glfwInit())
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
|
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetErrorCallback(error_callback);
|
|
||||||
|
|
||||||
if (major != 1 || minor != 0)
|
if (major != 1 || minor != 0)
|
||||||
{
|
{
|
||||||
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, major);
|
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, major);
|
||||||
|
Loading…
Reference in New Issue
Block a user