From 9ade61e0063a245a22fe7d387ec20116429c983a Mon Sep 17 00:00:00 2001 From: Quinn Date: Mon, 14 Apr 2025 14:45:11 +0200 Subject: [PATCH] add GLFW error callback --- src/error.h | 6 ++++++ src/main.c | 1 + 2 files changed, 7 insertions(+) diff --git a/src/error.h b/src/error.h index 24ee357..9ca5140 100644 --- a/src/error.h +++ b/src/error.h @@ -15,6 +15,7 @@ atrb_nonnull(1) atrb_format(printf, 1, 2) static inline void info(char const*, . atrb_nonnull(1) atrb_format(printf, 1, 2) static inline void warn(char const*, ...); atrb_nonnull(1) atrb_format(printf, 1, 2) static inline void error(char const*, ...); atrb_nonnull(1) atrb_format(printf, 1, 2) noreturn static inline void fatal(char const*, ...); +atrb_nonnull(2) static inline void error_callback(int err, char const* const msg); // macro to write fmt vardiac args to buf #define WRITE_VA_ARGS(buf, fmt) \ @@ -61,4 +62,9 @@ void fatal(char const* fmt, ...) { abort(); } +// callback for GLFW errors +void error_callback(int err, char const* const msg) { + fprintf(stderr, "\033[91mE: glfw returned (%i); \"%s\"\033[0m\n", err, msg); +} + #undef WRITE_VA_ARGS diff --git a/src/main.c b/src/main.c index 56a6f32..bff7628 100644 --- a/src/main.c +++ b/src/main.c @@ -7,6 +7,7 @@ struct renderdat rdat; // contains the relevant data needed for rendering, contains rubbish data until init was static inline int init(void) { + glfwSetErrorCallback(error_callback); glfwInitHint(GLFW_JOYSTICK_HAT_BUTTONS, GLFW_FALSE); // disable joystick buttons if (!glfwInit()) return 1; // initialize GLFW