views:

314

answers:

1

OpenGL ES 1.1 likes to crash my iPhone program if anything goes slightly wrong.

Usually it happens somewhere inside glDrawArrays, with several glDestroyContext calls on stack.

Usually I'm bisecting the problem by inserting

{
  GLint iErr = glGetError();
  if (iErr != GL_NO_ERROR)
  {
    NSLog(@"GL error: %d (0x%x)", iErr, iErr);
  }
}

all over the place.

However sometimes it is not enough. Are there any other ways to get useful diagnostics on the crash reasons?

A: 

Do you get any error messages in the console output? Just from the description, I wonder if you're getting a BAD_ACCESS exception. If my assumption is correct, you are probably passing a bad array to glVertexPointer, glColorPointer, or one of the other, related functions.

Am I correct in assuming that it dies in glDrawArrays and never comes back? In other words, there's no way to call glGetError after glDrawArrays because the program has already crashed?

Daniel Yankowsky
No extra console messages (that is, aside of the crash type -- that is usually bad access indeed). Usually it is either some bad input data, or I have forgotten to enable some state. But it takes time to find what gone wrong specifically. Usually I have to resort to binary search. :(
Alexander Gladysh
I would check to ensure that you aren't trying to draw more triangles than your buffers contain. It sounds like OpenGL is getting into memory that it shouldn't, which probably means that you told it that you have more vertices than you really have in the buffer.
Daniel Yankowsky