Andrea Sindico
Andrea Sindico

Reputation: 7440

Assertion Failure in -[CCSprite setTexture:]

I am having a problem with a cocos2d app for IPhone I am developing. The prolem comes out sometimes during a scene change. The app stucks and the console starts printing this statement:

Assertion failure in -[CCSprite setTexture:]

I would like you to suggest me the right way to debug it since the problem does not always happen and there is not a precise indication of where the bug might be.

Thank you in advance

... some hours after: The problem occurs after a memory warning. It its therefore due to the sprite cache which is flushed while an animation is exploiting a cached texture atlas and related sheet. What can I do to handle it?

Upvotes: 0

Views: 2096

Answers (1)

sergio
sergio

Reputation: 69047

I would set a breakpoint in [CCSprite setTexture:] and from there check the stack trace and go back to your offending call. Of course, this will only succeed in case the failure occurs.

In my cocos2d installation (0.9.5), asserts in setTexture can be:

NSAssert( ! usesBatchNode_, @"CCSprite: setTexture doesn't work when the sprite is rendered using a CCSpriteBatchNode");

// accept texture==nil as argument
NSAssert( !texture || [texture isKindOfClass:[CCTexture2D class]], @"setTexture expects a CCTexture2D. Invalid argument");

So you are doing either of those wrongly.

EDIT after you comment:

your appDelegate defines presumably:

 - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
[[CCDirector sharedDirector] purgeCachedData];
 }

try using:

[[CCTextureCache sharedTextureCache] removeUnusedTextures];

instead of [[CCDirector sharedDirector] purgeCachedData]. Hope things will improve.

Upvotes: 2

Related Questions