Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I trigger a breakpoint on OpenGL errors in Xcode 4?

Is there any way I can set a symbolic breakpoint that will trigger when any OpenGL function call sets any state other than GL_NO_ERROR? Initial evidence suggests opengl_error_break is intended to to serve just that purpose, but it doesn't break.

like image 258
Matt Wilding Avatar asked Dec 07 '11 23:12

Matt Wilding


2 Answers

Based on Lars' approach you can achieve this tracking of errors automatically, it is based on some preprocessor magic and generating stub functions.

I wrote a small Python script which processes the OpenGL header (I used the Mac OS X one in the example, but it should also work with the one of iOS).

The Python script generates two files, a header to include in your project everywhere where you call OpenGL like this (you can name the header however you want):

#include "gl_debug_overwrites.h"

The header contains macros and function declarations after this scheme:

#define glGenLists _gl_debug_error_glGenLists
GLuint _gl_debug_error_glGenLists(GLsizei range);

The script also produces a source file in the same stream which you should save separately, compile and link with your project.

This will then wrap all gl* functions in another function which is prefixed with _gl_debug_error_ which then checks for errors similar to this:

GLuint _gl_debug_error_glGenLists(GLsizei range) {
    GLuint var = glGenLists(range);
    CHECK_GL_ERROR();
    return var;
}
like image 191
Torsten Avatar answered Sep 22 '22 09:09

Torsten


Wrap your OpenGL calls to call glGetError after every call in debug mode. Within the wrapper method create a conditional breakpoint and check if the return value of glGetError is something different than GL_NO_ERROR.

Details:

Add this macro to your project (from OolongEngine project):

#define CHECK_GL_ERROR() ({ GLenum __error = glGetError(); if(__error) printf("OpenGL error 0x%04X in %s\n", __error, __FUNCTION__); (__error ? NO : YES); })

Search for all your OpenGL calls manually or with an appropriate RegEx. Then you have two options exemplary shown for the glViewport() call:

  1. Replace the call with glViewport(...); CHECK_GL_ERROR()
  2. Replace the call with glDebugViewport(...); and implement glDebugViewport as shown in (1).
like image 30
Lars Schneider Avatar answered Sep 21 '22 09:09

Lars Schneider