Ruud van Falier
Ruud van Falier

Reputation: 8877

Game running fine on iOS 4.3, but crashing on iOS 5 on glDrawArrays

I developed an iPhone game a year ago and decided to pick up where i left. So I downloaded the latest version of Xcode (4.4.1) which I run on Mac OS X 10.7.4 and I built my game using the iOS 5.1 SDK (building for iOS 4.0) and run it in the simulator on iOS 5.1 and... it crashes on the first glDrawArrays() call.

So I figured that was weird, because it surely ran perfectly fine when I last worked on it. I then tried running on iOS 4.3 and it works fine! Turns out it crashes from iOS. 5.0 and up. I also tried building for a higher target OS version, but that doesn't make any difference.

The application crashes at a gleRunVertexSubmitImmediate call (with a EXC_BAD_ACCESS message, address 0x0) which is executed by glDrawArrays. It always goes wrong at the first glDrawArrays call, cause if I comment the first one, it runs fine (black screen) until I initiate what was supposed to be the 2nd glDrawArrays call and it crashes again.

Did some inspection of the arrays that are loaded (texturepointers, vertices, gl context), but I can't spot any null references. Running with zombie enabled doesn't provide me with more info.

I wonder if anyone has experienced the same problem or has any idea what could cause it.

EDIT: Code example was request. It happens in the GLTexture.m (v1.7) that is issues by Apple, because that is the first point in code where glDrawArrays is called.

- (void) drawInRect:(CGRect)rect
{
    CLogGL();
    GLfloat  coordinates[] = {  0,      _maxT,
                                _maxS,  _maxT,
                                0,      0,
                                _maxS,  0  };
    GLfloat vertices[] = {  rect.origin.x,                          rect.origin.y,                          0.0,
                            rect.origin.x + rect.size.width,        rect.origin.y,                          0.0,
                            rect.origin.x,                          rect.origin.y + rect.size.height,       0.0,
                            rect.origin.x + rect.size.width,        rect.origin.y + rect.size.height,       0.0 };

    glBindTexture(GL_TEXTURE_2D, _name);
    glVertexPointer(3, GL_FLOAT, 0, vertices);
    glTexCoordPointer(2, GL_FLOAT, 0, coordinates);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);  // Crash happens here
}

EDIT: Screenshots of the stack trace: stacktrace1.jpg stacktrace2.jpg stacktrace3.jpg

EDIT: Seems that it crashes on 4.2.2 too (on my iPod touch), but still runs fine in 4.3 simulator.

Upvotes: 2

Views: 1584

Answers (1)

wasigh
wasigh

Reputation: 905

Perhaps your normal_array or color_array is enabled somewhere. Try disabling them:

glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);

If they are enabled but not set glDrawArrays will crash

Upvotes: 2

Related Questions