0

我能够在 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; }

任何想法为什么会发生这种情况?

4

1 回答 1

4

我可以通过调用 CCSequence::create() 来解决这个问题,例如:

CCSequence::create(explosionAnimate, callFuncN, NULL);

代替:

CCSequence::create(explosionAnimate, callFuncN);

我猜这与 CCFiniteAction 指针和 C++ 可变长度参数的性质有关。

于 2013-02-17T18:59:09.570 回答