Removed glfwGetError and glfwErrorString.
The cached error code cannot be made per-thread unless it required
glfwInit (due to lack of __thread on OS X), which would be confusing and
partially defeats the purpose of it.
Beginners would use the generic error string facility instead of the
error callback and then be confused by its nondescript messages.
Storing the provided error code from within the error callback, whether
globally or per-thread, requires just a few lines of code and hands
control to the user without compromising thread safety.
diff --git a/examples/boing.c b/examples/boing.c
index 5a1993f..f977112 100644
--- a/examples/boing.c
+++ b/examples/boing.c
@@ -572,17 +572,13 @@
/* Init GLFW */
if( !glfwInit() )
- {
- fprintf( stderr, "Failed to initialize GLFW\n" );
exit( EXIT_FAILURE );
- }
glfwWindowHint(GLFW_DEPTH_BITS, 16);
window = glfwCreateWindow( 400, 400, GLFW_WINDOWED, "Boing (classic Amiga demo)", NULL );
if (!window)
{
- fprintf( stderr, "Failed to open GLFW window\n" );
glfwTerminate();
exit( EXIT_FAILURE );
}
diff --git a/examples/triangle.c b/examples/triangle.c
index 3a1cef9..13ef0a9 100644
--- a/examples/triangle.c
+++ b/examples/triangle.c
@@ -10,24 +10,26 @@
#define GLFW_INCLUDE_GLU
#include <GL/glfw3.h>
+static void error_callback(int error, const char* description)
+{
+ fprintf(stderr, "Error: %s\n", description);
+}
+
int main(void)
{
int width, height, x;
GLFWwindow window;
+ glfwSetErrorCallback(error_callback);
+
// Initialise GLFW
if (!glfwInit())
- {
- fprintf(stderr, "Failed to initialize GLFW\n");
exit(EXIT_FAILURE);
- }
// Open a window and create its OpenGL context
window = glfwCreateWindow(640, 480, GLFW_WINDOWED, "Spinning Triangle", NULL);
if (!window)
{
- fprintf(stderr, "Failed to open GLFW window\n");
-
glfwTerminate();
exit(EXIT_FAILURE);
}
diff --git a/examples/wave.c b/examples/wave.c
index 7b4b4c3..28065d3 100644
--- a/examples/wave.c
+++ b/examples/wave.c
@@ -258,6 +258,16 @@
//========================================================================
+// Print errors
+//========================================================================
+
+static void error_callback(int error, const char* description)
+{
+ fprintf(stderr, "Error: %s\n", description);
+}
+
+
+//========================================================================
// Handle key strokes
//========================================================================
@@ -393,16 +403,15 @@
double t, dt_total, t_old;
int width, height;
+ glfwSetErrorCallback(error_callback);
+
if (!glfwInit())
- {
- fprintf(stderr, "GLFW initialization failed\n");
exit(EXIT_FAILURE);
- }
window = glfwCreateWindow(640, 480, GLFW_WINDOWED, "Wave Simulation", NULL);
if (!window)
{
- fprintf(stderr, "Could not open window\n");
+ glfwTerminate();
exit(EXIT_FAILURE);
}
diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h
index bd968a6..46db151 100644
--- a/include/GL/glfw3.h
+++ b/include/GL/glfw3.h
@@ -951,25 +951,6 @@
*/
GLFWAPI const char* glfwGetVersionString(void);
-/*! @brief Retrieves the latest error.
- * @return The latest @link errors error code @endlink.
- * @ingroup error
- *
- * @remarks This function may be called before @ref glfwInit.
- */
-GLFWAPI int glfwGetError(void);
-
-/*! @brief Retrieves a generic, human readable description of the specified error.
- * @param[in] error The @link errors error code @endlink to be described.
- * @return A UTF-8 encoded string describing the error.
- * @ingroup error
- *
- * @remarks This function may be called before @ref glfwInit.
- *
- * @remarks This function may be called from secondary threads.
- */
-GLFWAPI const char* glfwErrorString(int error);
-
/*! @brief Sets the error callback.
* @param[in] cbfun The new callback, or @c NULL to remove the currently set
* callback.
diff --git a/readme.html b/readme.html
index 8e25c74..d5e9d92 100644
--- a/readme.html
+++ b/readme.html
@@ -270,8 +270,7 @@
<li>Added <code>GLFWwindow</code> window handle type and updated window-related functions and callbacks to take a window handle</li>
<li>Added <code>glfwDefaultWindowHints</code> function for resetting all window hints to their default values</li>
<li>Added <code>glfwMakeContextCurrent</code> function for making the context of the specified window current</li>
- <li>Added <code>glfwGetError</code> and <code>glfwErrorString</code> error reporting functions and a number of error tokens</li>
- <li>Added <code>glfwSetErrorCallback</code> function and <code>GLFWerrorfun</code> type for receiving more specific and/or nested errors</li>
+ <li>Added <code>glfwSetErrorCallback</code> function and <code>GLFWerrorfun</code> type for receiving error descriptions</li>
<li>Added <code>glfwSetWindowUserPointer</code> and <code>glfwGetWindowUserPointer</code> functions for per-window user pointers</li>
<li>Added <code>glfwGetVersionString</code> function for determining which code paths were enabled at compile time</li>
<li>Added <code>glfwSetWindowPosCallback</code> function and <code>GLFWwindowposfun</code> type for reciving window position events</li>
diff --git a/src/init.c b/src/init.c
index 521674a..dbdbc48 100644
--- a/src/init.c
+++ b/src/init.c
@@ -51,15 +51,6 @@
//------------------------------------------------------------------------
-// The current GLFW error code
-// This is outside of _glfwLibrary so it can be initialized and usable
-// before glfwInit is called, which lets that function report errors
-// TODO: Make this thread-local
-//------------------------------------------------------------------------
-static int _glfwError = GLFW_NO_ERROR;
-
-
-//------------------------------------------------------------------------
// The current error callback
// This is outside of _glfwLibrary so it can be initialized and usable
// before glfwInit is called, which lets that function report errors
@@ -67,6 +58,40 @@
static GLFWerrorfun _glfwErrorCallback = NULL;
+//========================================================================
+// Returns a generic string representation of the specified error
+//========================================================================
+
+static const char* getErrorString(int error)
+{
+ switch (error)
+ {
+ case GLFW_NO_ERROR:
+ return "No error";
+ case GLFW_NOT_INITIALIZED:
+ return "The GLFW library is not initialized";
+ case GLFW_NO_CURRENT_CONTEXT:
+ return "There is no current context";
+ case GLFW_INVALID_ENUM:
+ return "Invalid argument for enum parameter";
+ case GLFW_INVALID_VALUE:
+ return "Invalid value for parameter";
+ case GLFW_OUT_OF_MEMORY:
+ return "Out of memory";
+ case GLFW_API_UNAVAILABLE:
+ return "The requested client API is unavailable";
+ case GLFW_VERSION_UNAVAILABLE:
+ return "The requested client API version is unavailable";
+ case GLFW_PLATFORM_ERROR:
+ return "A platform-specific error occurred";
+ case GLFW_FORMAT_UNAVAILABLE:
+ return "The requested format is unavailable";
+ }
+
+ return "ERROR: UNKNOWN ERROR TOKEN PASSED TO glfwErrorString";
+}
+
+
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
@@ -97,12 +122,10 @@
description = buffer;
}
else
- description = glfwErrorString(error);
+ description = getErrorString(error);
_glfwErrorCallback(error, description);
}
- else
- _glfwError = error;
}
@@ -188,54 +211,6 @@
//========================================================================
-// Returns the current error value
-// This function may be called without GLFW having been initialized
-//========================================================================
-
-GLFWAPI int glfwGetError(void)
-{
- int error = _glfwError;
- _glfwError = GLFW_NO_ERROR;
- return error;
-}
-
-
-//========================================================================
-// Returns a string representation of the specified error value
-// This function may be called without GLFW having been initialized
-//========================================================================
-
-GLFWAPI const char* glfwErrorString(int error)
-{
- switch (error)
- {
- case GLFW_NO_ERROR:
- return "No error";
- case GLFW_NOT_INITIALIZED:
- return "The GLFW library is not initialized";
- case GLFW_NO_CURRENT_CONTEXT:
- return "There is no current context";
- case GLFW_INVALID_ENUM:
- return "Invalid argument for enum parameter";
- case GLFW_INVALID_VALUE:
- return "Invalid value for parameter";
- case GLFW_OUT_OF_MEMORY:
- return "Out of memory";
- case GLFW_API_UNAVAILABLE:
- return "The requested client API is unavailable";
- case GLFW_VERSION_UNAVAILABLE:
- return "The requested client API version is unavailable";
- case GLFW_PLATFORM_ERROR:
- return "A platform-specific error occurred";
- case GLFW_FORMAT_UNAVAILABLE:
- return "The requested format is unavailable";
- }
-
- return "ERROR: UNKNOWN ERROR TOKEN PASSED TO glfwErrorString";
-}
-
-
-//========================================================================
// Sets the callback function for GLFW errors
// This function may be called without GLFW having been initialized
//========================================================================
diff --git a/tests/accuracy.c b/tests/accuracy.c
index d320f64..099a619 100644
--- a/tests/accuracy.c
+++ b/tests/accuracy.c
@@ -51,6 +51,11 @@
glfwSetWindowTitle(window, title);
}
+static void error_callback(int error, const char* description)
+{
+ fprintf(stderr, "Error: %s\n", description);
+}
+
static void window_size_callback(GLFWwindow window, int width, int height)
{
window_width = width;
@@ -80,18 +85,15 @@
GLFWwindow window;
int width, height;
+ glfwSetErrorCallback(error_callback);
+
if (!glfwInit())
- {
- fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
- }
window = glfwCreateWindow(window_width, window_height, GLFW_WINDOWED, "", NULL);
if (!window)
{
glfwTerminate();
-
- fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
}
diff --git a/tests/clipboard.c b/tests/clipboard.c
index c3746f1..7c93122 100644
--- a/tests/clipboard.c
+++ b/tests/clipboard.c
@@ -47,6 +47,11 @@
glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL);
}
+static void error_callback(int error, const char* description)
+{
+ fprintf(stderr, "Error: %s\n", description);
+}
+
static int window_close_callback(GLFWwindow window)
{
closed = GL_TRUE;
@@ -93,11 +98,6 @@
glViewport(0, 0, width, height);
}
-static void error_callback(int error, const char* description)
-{
- fprintf(stderr, "Error in %s\n", description);
-}
-
int main(int argc, char** argv)
{
int ch;
diff --git a/tests/defaults.c b/tests/defaults.c
index 8f08889..3b45769 100644
--- a/tests/defaults.c
+++ b/tests/defaults.c
@@ -72,16 +72,20 @@
{ 0, NULL }
};
+static void error_callback(int error, const char* description)
+{
+ fprintf(stderr, "Error: %s\n", description);
+}
+
int main(void)
{
int i, width, height;
GLFWwindow window;
+ glfwSetErrorCallback(error_callback);
+
if (!glfwInit())
- {
- fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
- }
glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
@@ -89,8 +93,6 @@
if (!window)
{
glfwTerminate();
-
- fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
}
diff --git a/tests/events.c b/tests/events.c
index 46bde2a..c79af8b 100644
--- a/tests/events.c
+++ b/tests/events.c
@@ -218,6 +218,11 @@
return result;
}
+static void error_callback(int error, const char* description)
+{
+ fprintf(stderr, "Error: %s\n", description);
+}
+
static void window_pos_callback(GLFWwindow window, int x, int y)
{
printf("%08x at %0.3f: Window position: %i %i\n",
@@ -344,11 +349,10 @@
setlocale(LC_ALL, "");
+ glfwSetErrorCallback(error_callback);
+
if (!glfwInit())
- {
- fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
- }
printf("Library initialized\n");
@@ -356,8 +360,6 @@
if (!window)
{
glfwTerminate();
-
- fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
}
diff --git a/tests/fsaa.c b/tests/fsaa.c
index 735a1f5..b564bfe 100644
--- a/tests/fsaa.c
+++ b/tests/fsaa.c
@@ -38,6 +38,11 @@
#include "getopt.h"
+static void error_callback(int error, const char* description)
+{
+ fprintf(stderr, "Error: %s\n", description);
+}
+
static void window_size_callback(GLFWwindow window, int width, int height)
{
glViewport(0, 0, width, height);
@@ -82,11 +87,10 @@
}
}
+ glfwSetErrorCallback(error_callback);
+
if (!glfwInit())
- {
- fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
- }
if (samples)
printf("Requesting FSAA with %i samples\n", samples);
@@ -99,8 +103,6 @@
if (!window)
{
glfwTerminate();
-
- fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
}
@@ -113,8 +115,6 @@
if (!glfwExtensionSupported("GL_ARB_multisample"))
{
glfwTerminate();
-
- fprintf(stderr, "Context reports GL_ARB_multisample is not supported\n");
exit(EXIT_FAILURE);
}
diff --git a/tests/fsfocus.c b/tests/fsfocus.c
index a87d136..c83e166 100644
--- a/tests/fsfocus.c
+++ b/tests/fsfocus.c
@@ -35,6 +35,11 @@
static GLboolean running = GL_TRUE;
+static void error_callback(int error, const char* description)
+{
+ fprintf(stderr, "Error: %s\n", description);
+}
+
static void window_focus_callback(GLFWwindow window, int focused)
{
printf("%0.3f: Window %s\n",
@@ -76,18 +81,15 @@
{
GLFWwindow window;
+ glfwSetErrorCallback(error_callback);
+
if (!glfwInit())
- {
- fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
- }
window = glfwCreateWindow(640, 480, GLFW_FULLSCREEN, "Fullscreen focus", NULL);
if (!window)
{
glfwTerminate();
-
- fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
}
diff --git a/tests/gamma.c b/tests/gamma.c
index 8b995af..324238d 100644
--- a/tests/gamma.c
+++ b/tests/gamma.c
@@ -52,6 +52,11 @@
glfwSetGamma(gamma_value);
}
+static void error_callback(int error, const char* description)
+{
+ fprintf(stderr, "Error: %s\n", description);
+}
+
static int window_close_callback(GLFWwindow window)
{
closed = GL_TRUE;
@@ -118,11 +123,10 @@
}
}
+ glfwSetErrorCallback(error_callback);
+
if (!glfwInit())
- {
- fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
- }
if (mode == GLFW_FULLSCREEN)
{
@@ -141,8 +145,6 @@
if (!window)
{
glfwTerminate();
-
- fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
}
diff --git a/tests/glfwinfo.c b/tests/glfwinfo.c
index 8db9911..bd0251d 100644
--- a/tests/glfwinfo.c
+++ b/tests/glfwinfo.c
@@ -257,10 +257,7 @@
glfwSetErrorCallback(error_callback);
if (!glfwInit())
- {
- fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
- }
if (major != 1 || minor != 0)
{
diff --git a/tests/iconify.c b/tests/iconify.c
index b0b6b6a..0432e60 100644
--- a/tests/iconify.c
+++ b/tests/iconify.c
@@ -42,6 +42,11 @@
printf("Usage: iconify [-h] [-f]\n");
}
+static void error_callback(int error, const char* description)
+{
+ fprintf(stderr, "Error: %s\n", description);
+}
+
static int window_close_callback(GLFWwindow window)
{
closed = GL_TRUE;
@@ -113,11 +118,10 @@
}
}
+ glfwSetErrorCallback(error_callback);
+
if (!glfwInit())
- {
- fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
- }
if (mode == GLFW_FULLSCREEN)
{
@@ -136,8 +140,6 @@
if (!window)
{
glfwTerminate();
-
- fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
}
diff --git a/tests/joysticks.c b/tests/joysticks.c
index 2b24368..d297a3f 100644
--- a/tests/joysticks.c
+++ b/tests/joysticks.c
@@ -47,6 +47,11 @@
static Joystick joysticks[GLFW_JOYSTICK_LAST - GLFW_JOYSTICK_1 + 1];
static int joystick_count = 0;
+static void error_callback(int error, const char* description)
+{
+ fprintf(stderr, "Error: %s\n", description);
+}
+
static void window_size_callback(GLFWwindow window, int width, int height)
{
glViewport(0, 0, width, height);
@@ -185,18 +190,15 @@
memset(joysticks, 0, sizeof(joysticks));
+ glfwSetErrorCallback(error_callback);
+
if (!glfwInit())
- {
- fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
- }
window = glfwCreateWindow(640, 480, GLFW_WINDOWED, "Joystick Test", NULL);
if (!window)
{
glfwTerminate();
-
- fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
}
diff --git a/tests/peter.c b/tests/peter.c
index 30690e6..d7209e3 100644
--- a/tests/peter.c
+++ b/tests/peter.c
@@ -56,6 +56,11 @@
}
}
+static void error_callback(int error, const char* description)
+{
+ fprintf(stderr, "Error: %s\n", description);
+}
+
static void cursor_position_callback(GLFWwindow window, int x, int y)
{
printf("Cursor moved to: %i %i (%i %i)\n", x, y, x - cursor_x, y - cursor_y);
@@ -111,16 +116,13 @@
int main(void)
{
+ glfwSetErrorCallback(error_callback);
+
if (!glfwInit())
- {
- fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
- }
if (!open_window())
{
- fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
-
glfwTerminate();
exit(EXIT_FAILURE);
}
@@ -139,8 +141,6 @@
glfwDestroyWindow(window_handle);
if (!open_window())
{
- fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
-
glfwTerminate();
exit(EXIT_FAILURE);
}
diff --git a/tests/reopen.c b/tests/reopen.c
index 212c108..cd08548 100644
--- a/tests/reopen.c
+++ b/tests/reopen.c
@@ -54,6 +54,11 @@
}
}
+static void error_callback(int error, const char* description)
+{
+ fprintf(stderr, "Error: %s\n", description);
+}
+
static void window_size_callback(GLFWwindow window, int width, int height)
{
glViewport(0, 0, width, height);
@@ -85,19 +90,13 @@
double base;
if (!glfwInit())
- {
- fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
return GL_FALSE;
- }
base = glfwGetTime();
window_handle = glfwCreateWindow(width, height, mode, "Window Re-opener", NULL);
if (!window_handle)
- {
- fprintf(stderr, "Failed to open %s mode GLFW window: %s\n", get_mode_name(mode), glfwErrorString(glfwGetError()));
return GL_FALSE;
- }
glfwMakeContextCurrent(window_handle);
glfwSwapInterval(1);
@@ -129,6 +128,8 @@
{
int count = 0;
+ glfwSetErrorCallback(error_callback);
+
for (;;)
{
if (!open_window(640, 480, (count & 1) ? GLFW_FULLSCREEN : GLFW_WINDOWED))
diff --git a/tests/sharing.c b/tests/sharing.c
index 0042a85..b77aaf2 100644
--- a/tests/sharing.c
+++ b/tests/sharing.c
@@ -39,6 +39,11 @@
static GLFWwindow windows[2];
static GLboolean closed = GL_FALSE;
+static void error_callback(int error, const char* description)
+{
+ fprintf(stderr, "Error: %s\n", description);
+}
+
static void key_callback(GLFWwindow window, int key, int action)
{
if (action == GLFW_PRESS && key == GLFW_KEY_ESCAPE)
@@ -128,17 +133,14 @@
{
GLuint texture;
+ glfwSetErrorCallback(error_callback);
+
if (!glfwInit())
- {
- fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
- }
windows[0] = open_window("First", NULL, 0, 0);
if (!windows[0])
{
- fprintf(stderr, "Failed to open first GLFW window: %s\n", glfwErrorString(glfwGetError()));
-
glfwTerminate();
exit(EXIT_FAILURE);
}
@@ -152,8 +154,6 @@
windows[1] = open_window("Second", windows[0], WIDTH + 50, 0);
if (!windows[1])
{
- fprintf(stderr, "Failed to open second GLFW window: %s\n", glfwErrorString(glfwGetError()));
-
glfwTerminate();
exit(EXIT_FAILURE);
}
diff --git a/tests/tearing.c b/tests/tearing.c
index 63ece2b..8ab6a1d 100644
--- a/tests/tearing.c
+++ b/tests/tearing.c
@@ -48,6 +48,11 @@
glfwSetWindowTitle(window, title);
}
+static void error_callback(int error, const char* description)
+{
+ fprintf(stderr, "Error: %s\n", description);
+}
+
static void window_size_callback(GLFWwindow window, int width, int height)
{
glViewport(0, 0, width, height);
@@ -64,17 +69,14 @@
float position;
GLFWwindow window;
+ glfwSetErrorCallback(error_callback);
+
if (!glfwInit())
- {
- fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
- }
window = glfwCreateWindow(640, 480, GLFW_WINDOWED, "", NULL);
if (!window)
{
- fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
-
glfwTerminate();
exit(EXIT_FAILURE);
}
diff --git a/tests/threads.c b/tests/threads.c
index 8b06b1d..9cc7897 100644
--- a/tests/threads.c
+++ b/tests/threads.c
@@ -47,6 +47,11 @@
static volatile GLboolean running = GL_TRUE;
+static void error_callback(int error, const char* description)
+{
+ fprintf(stderr, "Error: %s\n", description);
+}
+
static int thread_main(void* data)
{
const Thread* thread = (const Thread*) data;
@@ -80,12 +85,10 @@
};
const int count = sizeof(threads) / sizeof(Thread);
+ glfwSetErrorCallback(error_callback);
+
if (!glfwInit())
- {
- fprintf(stderr, "Failed to initialize GLFW: %s\n",
- glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
- }
for (i = 0; i < count; i++)
{
@@ -97,8 +100,7 @@
NULL);
if (!threads[i].window)
{
- fprintf(stderr, "Failed to open GLFW window: %s\n",
- glfwErrorString(glfwGetError()));
+ glfwTerminate();
exit(EXIT_FAILURE);
}
@@ -106,6 +108,8 @@
thrd_success)
{
fprintf(stderr, "Failed to create secondary thread\n");
+
+ glfwTerminate();
exit(EXIT_FAILURE);
}
}
diff --git a/tests/title.c b/tests/title.c
index 62690f9..b23f0ab 100644
--- a/tests/title.c
+++ b/tests/title.c
@@ -32,6 +32,11 @@
#include <stdio.h>
#include <stdlib.h>
+static void error_callback(int error, const char* description)
+{
+ fprintf(stderr, "Error: %s\n", description);
+}
+
static void window_size_callback(GLFWwindow window, int width, int height)
{
glViewport(0, 0, width, height);
@@ -41,17 +46,14 @@
{
GLFWwindow window;
+ glfwSetErrorCallback(error_callback);
+
if (!glfwInit())
- {
- fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
- }
window = glfwCreateWindow(400, 400, GLFW_WINDOWED, "English 日本語 русский язык 官話", NULL);
if (!window)
{
- fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
-
glfwTerminate();
exit(EXIT_FAILURE);
}
diff --git a/tests/windows.c b/tests/windows.c
index 187248c..d000683 100644
--- a/tests/windows.c
+++ b/tests/windows.c
@@ -40,18 +40,21 @@
"Quux"
};
+static void error_callback(int error, const char* description)
+{
+ fprintf(stderr, "Error: %s\n", description);
+}
+
int main(void)
{
int i;
GLboolean running = GL_TRUE;
GLFWwindow windows[4];
+ glfwSetErrorCallback(error_callback);
+
if (!glfwInit())
- {
- fprintf(stderr, "Failed to initialize GLFW: %s\n",
- glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
- }
for (i = 0; i < 4; i++)
{
@@ -60,9 +63,6 @@
windows[i] = glfwCreateWindow(200, 200, GLFW_WINDOWED, titles[i], NULL);
if (!windows[i])
{
- fprintf(stderr, "Failed to open GLFW window: %s\n",
- glfwErrorString(glfwGetError()));
-
glfwTerminate();
exit(EXIT_FAILURE);
}