我能够在iPhone模拟器上运行此代码而不会出现错误。但是,当我在iPhone上运行它时,我收到一个EXC_BAD_ACCESS错误。这是代码:
CCAnimate * explosionAnimate = CCAnimate::create(explosionAnimation);
CCCallFuncN * callFuncN = CCCallFuncN::create(this,callfuncN_selector(GameLayer::removeChildFromParent));
CCFiniteTimeAction * explosionSequence = CCSequence::create(explosionAnimate, callFuncN);
CCSprite * explosionSprite = CCSprite::createWithSpriteFrameName("explosion_frame_1");
addChild(explosionSprite);
explosionSprite->setPosition(point);
explosionSprite->runAction(explosionSequence);
}
void GameLayer::removeChildFromParent(CCNode * child)
{
child->removeFromParent();
}
调用CCSequence :: create(...)时发生错误。通过CCSequence进行调试:: create(...)
CCFiniteTimeAction* CCSequence::create(CCFiniteTimeAction *pAction1, va_list args)
{
CCFiniteTimeAction *pNow;
CCFiniteTimeAction *pPrev = pAction1;
while (pAction1)
{
pNow = va_arg(args, CCFiniteTimeAction*);
if (pNow)
{
pPrev = createWithTwoActions(pPrev, pNow);
}
else
{
break;
}
}
return pPrev;
}
我看到“createWithTwoActions”被叫两次。这似乎不对。在第二次调用“createWithTwoActions”。错误发生在CCFiniteTimeAction中,特别是在getDuration()内联函数中:
inline float getDuration(void) { return m_fDuration; }
为什么会发生这种情况?
答案 0 :(得分:4)
我能够通过调用CCSequence :: create()来解决这个问题:
CCSequence::create(explosionAnimate, callFuncN, NULL);
而不是:
CCSequence::create(explosionAnimate, callFuncN);
我猜测这与CCFiniteAction指针和C ++可变长度参数的性质有关。