cocos2d-x:EXC_BAD_ACCESS问题

时间:2014-04-29 14:52:10

标签: android c++ cocos2d-x nsuserdefaults exc-bad-access

我有一个EXC_BAD_ACCESS(代码= 1 ...)有时代码= 2使用cocos2d-x。例如,当我这样做时出现此错误:

void HelloWorld::gameLogic(float dt)
{
    if (gameState == GameFinish)
    {

        seaBaseWidth = seaBase->getPositionX();
        seaBase->stopAllActions();
        CCUserDefault::sharedUserDefault()->setBoolForKey("isHaveHistoryOfSeaBaseWidth", true);
        CCUserDefault::sharedUserDefault()->setFloatForKey("basePositionX", seaBaseWidth);
        CCUserDefault::sharedUserDefault()->flush();

        if (!CCUserDefault::sharedUserDefault()->getBoolForKey("isHaveHistoryScore"))
        {
            int bestSocre = CCUserDefault::sharedUserDefault()->getIntegerForKey("HighestScore");
            if (bestSocre < bird->score)
            {

                CCUserDefault::sharedUserDefault()->setBoolForKey("isHaveHistorySchore", true);
                CCUserDefault::sharedUserDefault()->setIntegerForKey("HighestScore", bird->score);
                CCUserDefault::sharedUserDefault()->flush();

            }

        }

        CCUserDefault::sharedUserDefault()->setBoolForKey("isHaveHistoryCurrentSchore", true);
        CCUserDefault::sharedUserDefault()->setIntegerForKey("currentScore", bird->score);
        CCUserDefault::sharedUserDefault()->flush();

        CCDelayTime* tmeDelay = CCDelayTime::create(1.4f);
        CCCallFunc* progressIncreaseCall = CCCallFunc::create(this, callfunc_selector(HelloWorld::GameOverScoreScreenStart
        ));
        CCSequence *newSeq = CCSequence::create(tmeDelay, progressIncreaseCall);
        this->runAction(newSeq);
    }

}

以下是callfunc_selector的代码:

void HelloWorld::GameOverScoreScreenStart()
{
    CCDirector::sharedDirector()->replaceScene(Score::scene());
}

这个方法在CCDictionary.cpp中崩溃了:

unsigned int CCDictionary::count()
{
    return HASH_COUNT(m_pElements);
}

任何人都可以帮我吗?

1 个答案:

答案 0 :(得分:0)

尝试

 CCSequence *newSeq = CCSequence::create(tmeDelay, progressIncreaseCall, NULL);

而不是

 CCSequence *newSeq = CCSequence::create(tmeDelay, progressIncreaseCall);

希望这有帮助。