CCAniamtion member function call cause ASSERT failure, is it a BUG

CCAniamtion member function call cause ASSERT failure, is it a BUG
0.0 0


My funtion to create an animation is below:
CCAnimation * AnimationManager::createHeroMoveAnimationByDirection(HeroDirection direction)
CCTexture2D * heroTexture=CCTextureCache::sharedTextureCache()>addImage;
CCSpriteFrame * frames[4];
CCArray * animFrames=CCArray::create;
CCAnimation * animation=new CCAnimation();
return animation;

when I call such an animation’s member funtion as below

CCSprite::createWithSpriteFrame((CCSpriteFrame *)animation->getFrames()->objectAtIndex());

such a sentence cause ASSERT failure saying “Reference count should be greater than 0”

who knows what is the problem? is it a BUG?


this sentence release the frames and its reference count will be 0, you should release it after return or use “autorelease” before return


Em….I comment out the animation~~>release; the ASSERT failure problem still occurs;
And then I replace the animation~~>release(); to animation->autorelease() the ASSERT failure still occurs.

I strongly think that is a BUG!


see the callstack that which node break the assert, the animation, frame or sprite?


Sorry Debuger jump into assemble code ,that make me confused about where my code is going to.:frowning:


You call release to often on an object (i.e. you are trying to release an object that has already been deleted)

Take a look at this post on how the memory management in cocos2dx works:

Your debugger should provide you with a callstack. It will stop in some assembly code (thats most certainly the assert calling abort() in the C-library)
But you should be able to see the call stack on where the release call came from.

If you can test your project on linux, I would recommend using valgrind to profile your code, as it will show you where and when the object has been released before.


Thank you! I will try your advice, If I solve this problem, I will post my solution in this thread.


I think maybe “CCAnimation * animation=new CCAnimation();” this sentence was the problem.
try “animation->autorelease()” or “CCAnimation * animation= CCAnimation::createWithSpriteFrames(…)” (createWithSpriteFrames will call “autorelease” method)
it looks that “animation” was released after call.


li jia I have try your advice but it is still a problem.I think the reason lie in the access violation just like Andre Rudlaff said.:slight_smile: