I can’t quiet figure how to debug this. I have a CCScene running and when the scene is replaced I get the following error message.
The scene has a sprite batch node where the CCSpriteSubclass is added.
That’s the cleanup method and below that you will find the assertion failure message:
-(void) cleanup
{
[[GameController sharedGameController].musicLayer removeMusicSourceForKey:backgroundMusicFileName];
[CCTextureCache purgeSharedTextureCache];
[CCSpriteFrameCache purgeSharedSpriteFrameCache];
[CCAnimationCache purgeSharedAnimationCache];
// [[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
[super cleanup];
}
The batch node is created as following in the initWithId:(int)sceneId method:
//Prepare sprites sheets for the rest of the game art
[frameCache addSpriteFramesWithFile:[NSString stringWithFormat:@"art%i-hd.plist", sceneId]];
sharedSpriteMainBatchNode = [CCSpriteBatchNode batchNodeWithFile:[NSString stringWithFormat:@"art%i-hd.png", sceneId]];
And then I add all CCSpriteSubclass objects.
That’s the assertion failure message:
** Assertion failure in -[CCSpriteSubclass setTexture:], /Users/xxx/Desktop/xxx/xxx/libs/cocos2d/CCSprite.m:934
2012-12-03 12:54:33.335 RockTale[869:707] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'CCSprite: Batched sprites should use the same texture as the batchnode'
*** First throw call stack:
(0x338d28bf 0x303c61e5 0x338d27b9 0x311193b3 0x9ad43 0x9a2fb 0x4bca3 0x44ddf 0x38b07 0x503f7 0x94c03 0xbbeed 0xbcfe7 0x34fb7423 0x34fb7379 0x31b4cf93 0x36e52891 0x3389bf43 0x338a6553 0x338a64f5 0x338a5343 0x338284dd 0x338283a5 0x37f9afcd 0x3128b743 0x2edf 0x2ea0)
terminate called throwing an exception(lldb)
EDIT: Added a breakpoint to the setTexture method and here is what I “DON’t” see 🙂

EDIT 2: I whish I could manage to retrieve the full stacktrace like in Java.. I have asked this in a different question and I was told I should add a global exception.. I still need to figure out how to retrieve the stacktrace..
I solved this problem in the same way as here. It was due to the fact that sprite frames where referred while the previous class was replacing the existing one and hence the previous class cleanup method was calling the purge frame cache which was consequently removing the yet unused sprite frames which where being loaded in memory by the newly created object.