diff --git a/src/error.c b/src/error.c index 062fb76a..a1af3917 100644 --- a/src/error.c +++ b/src/error.c @@ -29,6 +29,9 @@ #include "internal.h" +#include +#include + ////////////////////////////////////////////////////////////////////////// ////// GLFW internal API ////// @@ -49,11 +52,30 @@ static GLFWerrorfun _glfwErrorCallback = NULL; // This function may be called without GLFW having been initialized //======================================================================== -void _glfwSetError(int error, const char* description) +void _glfwSetError(int error, const char* format, ...) { if (_glfwErrorCallback) { - if (!description) + char buffer[16384]; + const char* description; + + // We would use vasprintf here if msvcrt supported it + + if (format) + { + int count; + va_list vl; + + va_start(vl, format); + count = vsnprintf(buffer, sizeof(buffer), format, vl); + va_end(vl); + + if (count < 0) + buffer[sizeof(buffer) - 1] = '\0'; + + description = buffer; + } + else description = glfwErrorString(error); _glfwErrorCallback(error, description); diff --git a/src/internal.h b/src/internal.h index fc036bc0..4e18c93c 100644 --- a/src/internal.h +++ b/src/internal.h @@ -338,7 +338,7 @@ void _glfwPlatformCopyContext(_GLFWwindow* src, _GLFWwindow* dst, unsigned long void _glfwSplitBPP(int bpp, int* red, int* green, int* blue); // Error handling (error.c) -void _glfwSetError(int error, const char* description); +void _glfwSetError(int error, const char* format, ...); // Window management (window.c) void _glfwSetDefaultWindowHints(void);