add GLFW error callback

This commit is contained in:
Quinn
2025-04-14 14:45:11 +02:00
committed by Quinn
parent 7c4ba05eee
commit 9ade61e006
2 changed files with 7 additions and 0 deletions

View File

@@ -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 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) static inline void error(char const*, ...);
atrb_nonnull(1) atrb_format(printf, 1, 2) noreturn static inline void fatal(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 // macro to write fmt vardiac args to buf
#define WRITE_VA_ARGS(buf, fmt) \ #define WRITE_VA_ARGS(buf, fmt) \
@@ -61,4 +62,9 @@ void fatal(char const* fmt, ...) {
abort(); 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 #undef WRITE_VA_ARGS

View File

@@ -7,6 +7,7 @@
struct renderdat rdat; // contains the relevant data needed for rendering, contains rubbish data until init was struct renderdat rdat; // contains the relevant data needed for rendering, contains rubbish data until init was
static inline int init(void) { static inline int init(void) {
glfwSetErrorCallback(error_callback);
glfwInitHint(GLFW_JOYSTICK_HAT_BUTTONS, GLFW_FALSE); // disable joystick buttons glfwInitHint(GLFW_JOYSTICK_HAT_BUTTONS, GLFW_FALSE); // disable joystick buttons
if (!glfwInit()) return 1; // initialize GLFW if (!glfwInit()) return 1; // initialize GLFW