mirror of
https://github.com/gwm17/glfw.git
synced 2024-11-26 20:28:49 -05:00
Added formatting to error string.
This commit is contained in:
parent
208377d08e
commit
ba941b2fc8
26
src/error.c
26
src/error.c
|
@ -29,6 +29,9 @@
|
|||
|
||||
#include "internal.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// 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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user