断言失败 - [CCSprite setTexture:]

时间:2011-06-25 14:33:23

标签: iphone ios cocos2d-iphone

我正在开发的iPhone的cocos2d应用程序出现问题。在场景变化期间,有时会出现问题。应用程序停滞不前,控制台开始打印此声明:

断言失败 - [CCSprite setTexture:]

我希望您建议我正确的调试方法,因为问题并不总是发生,并且没有准确指示错误的位置。

提前谢谢

......几小时后:内存警告后出现问题。因此,它是由于在动画利用缓存的纹理图集和相关工作表时刷新的精灵缓存。我能做些什么来处理它?<​​/ p>

1 个答案:

答案 0 :(得分:2)

我会在[CCSprite setTexture:]中设置一个断点,并从那里检查堆栈跟踪并返回到您的违规呼叫。当然,这只有在失败发生时才会成功。

在我的cocos2d安装(0.9.5)中,setTexture中的断言可以是:

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");

所以你错误地做了其中任何一个。

评论后编辑:

你的appDelegate大概定义了:

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

尝试使用:

[[CCTextureCache sharedTextureCache] removeUnusedTextures];

而不是[[CCDirector sharedDirector] purgeCachedData]。希望事情会有所改善。