runAction Crashes!!!


#1

I create an action, and when some event happen, I let a sprite to run this action, BUT it crashes.
After I review my code, I found if I let a node to run an action, and this node’s scene have already running, it will crashes.
But if I let a node to run an action which is not in a running scene, then I let its scene running by call CCDirector::replaceScene.
It won’t crashes.

I did a test in your HelloWorld project to prove this situation.
Create an action in HelloWorld::init(), like: m_pAction = CCMoveBy::actionWithDuration(1,ccp(200,0));
change HelloWorld::menuCloseCallback to:
void HelloWorld::menuCloseCallback(CCObject* pSender)
{
pLabel->runAction(pAction);//let pLabel to be data member of class HelloWorld
}

When you click X button, it will crashes.
But if you remove “pLabel->runAction(pAction)” to HelloWorld::init(), it won’t crash, and the label is moving to right.

Did actions can’t start after the scene begin running? If so that will be too bad!

BTW, crashes at method ccArrayAppendObject.


#2

Modify your code like this:

  1. In function HelloWorld::init():


    m_pAction = CCMoveBy::actionWithDuration(1,ccp(200,0));
    m_pAction->retain();

  2. In destructors of HelloWorld:

    HelloWorld::~HelloWorld()
    {
    if (m_pAction)
    {
    m_pAction->release();
    }
    }

But I recommend that you had better use one action only once.
Because of once you run a action, the data of the action maybe wrong when you use it again.

Hope it’s helpful!