]> git.sesse.net Git - movit/commitdiff
Make the error printed on check_error() slightly friendlier: Include the enum if...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 26 Jul 2016 13:30:56 +0000 (15:30 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 26 Jul 2016 13:30:56 +0000 (15:30 +0200)
defs.h
util.cpp
util.h

diff --git a/defs.h b/defs.h
index ad1826cb4cec811379247c707d5cf7ee8140073f..155ef9b09544e075cf8615e040c9c459768ee22e 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -5,8 +5,10 @@
 
 #ifdef __GNUC__
 #define MUST_CHECK_RESULT __attribute__((warn_unused_result))
 
 #ifdef __GNUC__
 #define MUST_CHECK_RESULT __attribute__((warn_unused_result))
+#define DOES_NOT_RETURN __attribute__((noreturn))
 #else
 #define MUST_CHECK_RESULT 
 #else
 #define MUST_CHECK_RESULT 
+#define DOES_NOT_RETURN
 #endif
 
 #endif  // !defined(_MOVIT_DEFS_H)
 #endif
 
 #endif  // !defined(_MOVIT_DEFS_H)
index 3141f8d2c5eb388aec128f31b6218c06c0b1bb8d..3bbc86963f33b35d624daf833e675799ff040dbf 100644 (file)
--- a/util.cpp
+++ b/util.cpp
@@ -354,4 +354,39 @@ void *get_gl_context_identifier()
 #endif
 }
 
 #endif
 }
 
+void abort_gl_error(GLenum err, const char *filename, int line)
+{
+       const char *err_text = "unknown";
+
+       // All errors listed in the glGetError(3G) man page.
+       switch (err) {
+       case GL_NO_ERROR:
+               err_text = "GL_NO_ERROR";  // Should not happen.
+               break;
+       case GL_INVALID_ENUM:
+               err_text = "GL_INVALID_ENUM";
+               break;
+       case GL_INVALID_VALUE:
+               err_text = "GL_INVALID_VALUE";
+               break;
+       case GL_INVALID_OPERATION:
+               err_text = "GL_INVALID_OPERATION";
+               break;
+       case GL_INVALID_FRAMEBUFFER_OPERATION:
+               err_text = "GL_INVALID_FRAMEBUFFER_OPERATION";
+               break;
+       case GL_OUT_OF_MEMORY:
+               err_text = "GL_OUT_OF_MEMORY";
+               break;
+       case GL_STACK_UNDERFLOW:
+               err_text = "GL_STACK_UNDERFLOW";
+               break;
+       case GL_STACK_OVERFLOW:
+               err_text = "GL_STACK_OVERFLOW";
+               break;
+       }
+       fprintf(stderr, "GL error 0x%x (%s) at %s:%d\n", err, err_text, filename, line);
+       abort();
+}
+
 }  // namespace movit
 }  // namespace movit
diff --git a/util.h b/util.h
index f5b5dd368f4665c25d2e3c438714c2696cf90234..45fe6ba922b9728c5ac827ddb4b4d63a13a8ad11 100644 (file)
--- a/util.h
+++ b/util.h
@@ -8,6 +8,7 @@
 #include <stdlib.h>
 #include <Eigen/Core>
 #include <string>
 #include <stdlib.h>
 #include <Eigen/Core>
 #include <string>
+#include "defs.h"
 
 #define BUFFER_OFFSET(i) ((char *)NULL + (i))
 
 
 #define BUFFER_OFFSET(i) ((char *)NULL + (i))
 
@@ -93,12 +94,15 @@ unsigned next_power_of_two(unsigned v);
 // back into anything you intend to pass into OpenGL.
 void *get_gl_context_identifier();
 
 // back into anything you intend to pass into OpenGL.
 void *get_gl_context_identifier();
 
+// Used in the check_error() macro, below.
+void abort_gl_error(GLenum err, const char *filename, int line) DOES_NOT_RETURN;
+
 }  // namespace movit
 
 #ifdef NDEBUG
 #define check_error()
 #else
 }  // namespace movit
 
 #ifdef NDEBUG
 #define check_error()
 #else
-#define check_error() { int err = glGetError(); if (err != GL_NO_ERROR) { printf("GL error 0x%x at %s:%d\n", err, __FILE__, __LINE__); abort(); } }
+#define check_error() { GLenum err = glGetError(); if (err != GL_NO_ERROR) { movit::abort_gl_error(err, __FILE__, __LINE__); } }
 #endif
 
 // CHECK() is like assert(), but retains any side effects no matter the compilation mode.
 #endif
 
 // CHECK() is like assert(), but retains any side effects no matter the compilation mode.