I have an AtlasSpriteManager that contains many objects that were inherited from AtlasSprite. When the player runs into them I try to remove them from their AtlasSpriteManager, and the program crashes, like so:
[manager removeChild:nodeToRemove cleanup:YES];
If I set cleanup to NO, the program doesn't immediately crash, but rather occasionally crashes when it tries to remove these nodes. So with cleanup set to YES, I stepped through the program to see exactly where the crash happened.
On AtlasSpriteManager.m, line 209, it gives me EXC_BAD_ACCESS at this line:
NSUInteger index= sprite.atlasIndex;
So it looks like sprite.atlasIndex (or nodeToRemove.atlasIndex) was already deallocated sometime before, but I don't understand what atlasIndex is.
And the weird thing is I'm doing the exact same thing with another object that's inherited from AtlasSprite, and removing it from its own AtlasSpriteManager in the same way (with cleanup:YES) when the player runs into it, and it's working fine there. And the two objects don't have any huge differences. I don't understand...
Any help is appreciated!