I have finally found an answer to this. Well, the first clue is that the error is EXC_BAD_ACCESS. That almost always means I'm trying to access memory where there's not an object. Maybe a corrupted pointer, or an object gone away (been deallocated or lost the reference to it).
Going farther down the trace, it appears to be related to texture loading in some way. So I started by looking at any place where I were trying to load/preload textures, create sprites, etc. But it looks like it may be inside the prerender/render loop, which may mean it's not me explicitly loading textures, but Sprite Kit trying to load textures dynamically when needed.
I've tried removing some of the sprites until it doesn't crash, to narrow down which one is giving you the issue and I've finally found it was my hero movement. For his animation, I use a @propertie int _imgNum ;
And add it to a [NSString stringWithFormat:@"image%d",_imgNum];
so the _imgNum is the number of the image.
I initialize _imgNum at the beginning of the scene and increment it everytime I use it (in didSimulatePhysics()
and in touchedMovedWithEvent()
).
Sometimes the app don't find the image and that's when it crash, but I still don't get why can't load images.
I'll better show the code.
if(_imgNum >= 1 && _imgNum <= 12 )
{
[[self childNodeWithName:@"hero"]runAction:[SKAction setTexture:[SKTexture textureWithImageNamed:[NSString stringWithFormat:@"heroRunnning%d",_imgNum]]]];
_imgNum++;
if(_imgNum >= 12)
{
_imgNum = 1;
}
}