Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 7 and Cocos2d, exc_bad_access on glDrawElements completely random

I've worked on a game and I've tested it with the previous version of iOS, played hundreds of times and I've seen not even a single crash, after I've installed iOS7 and updated xcode I've just tried my app and... now sometimes it crash. The crashes are not happening in a particular moment or action, they're just completely random, sometimes it crash instantly, sometimes after 2-3 games, I've tried to do the same things to check if it's something in particular but seems to be not, or atleast not something noticeable in this way. I'm using sprites and batchnodes in the game scene.

Exactly in this line of code (around 522) in the CCTextureAtlas.m file:

glDrawElements(GL_TRIANGLES, (GLsizei) n*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(_indices[0])) );

since I didn't make any changes to the code I highly doubt that can be something I did, probably it's something related with the changes in iOS7 that affects cocos2d? I'm not even expert with opengl so I have hard time to understand what's happening...

obviously in the game I have some animations ongoing...

additional info:

  • this is NOT happening after a memory warning (I've not memory warning at all).
like image 611
Adarkuccio Avatar asked Oct 07 '13 23:10

Adarkuccio


1 Answers

Adding ccGLBindVAO(0); after every call to glDeleteVertexArrays(1, &_VAOname);, stopped the crashes.

There are three files with this call:

 CCDrawNode:164
 CCTextureAtlas:142
 CCParticleSystemQuad:164
 CCParticleSystemQuad:229
 CCParticleSystemQuad:492

Like so in CCTextureAtlas:

#if CC_TEXTURE_ATLAS_USE_VAO
    glDeleteVertexArrays(1, &_VAOname);
    ccGLBindVAO(0);
#endif

I'm using cocos2d-iphone classic 2.2.

The code was here: https://github.com/jllust/cocos2d-x/commit/1f3c1145362c921bf5232c4ffbca4a5245042bae

I made a cocos2d-iphone-classic pull request: https://github.com/zeraien/cocos2d-iphone-classic/commit/817a9c14a3aa1d4c162071521e45e2fcce473d77

like image 182
zeraien Avatar answered Oct 04 '22 21:10

zeraien