CCTargetedAction bug?

CCTargetedAction bug?
0.0 0


A very simple example:

CCLayer::init() { ... CCSprite* r = CCSprite::create("xxx"); this->addChild(r); CCSprite* e = CCSprite::create("yyy"); this->runAction(CCTargetedAction::create(e, CCCallFuncN::create(r, callfuncN_selector(CCSprite::addChild)))); // CCSprite::addChild will be called twice e->runAction(CCCallFuncN::create(r, callfuncN_selector(CCSprite::addChild))); // ok }

CCTargetedAction will make “r->addChild(e)” called twice, then CCAssert will fail. Anyone help me to find out the reason?


yeah i had this bug too - i am now using something like
std::function<void(Node*)> fn1 = std::bind((void (Sprite::*)(Node*))&Sprite::addChild, r, e); // cast required as the function is overloaded

have you raised a defect? it seems the isDone in actioninterval returns false the first time for targetedaction (as duration = epsilon and elapsed = 0 and it checks if elapsed >= duration.

not sure as i am not familiar with cocos code. but
i think targetedaction implementing isDone as
bool TargetedAction::isDone(void) const
return _action->isDone();

solves the issue


so i read the code a bit more and looks like this is happening.

targetedaction init with duration calls actioninterval::initwithduration which sets duration to FLT_EPSILON (as duration is 0 for the callfunc) and elapsed = 0

actionmanager::update has this loop

foreach target
*currentTarget~~>currentAction~~>step; // first time elapse = 0 and then elapsed += dt
if ) { //for actioninterval is done is elapsedtime >= duration


so looks like this problem will only occur for targetedaction when it has sub actions with no duration (ex the callfunc* maybe sequence of them etc)