Cocos2d-x在某些设备上运行时出现错误致命信号11(sigsegv)崩溃

时间:2014-06-20 02:26:48

标签: android cocos2d-x

我是cocos2d-x的最新版本。在我的游戏中,我想在每次创建精灵并控制位置的精灵以找出游戏结束。我的游戏在ios上运行良好但在某些Android设备上崩溃时出现错误致命信号11(sigsegv)。我使用ndk_stack进行调试,它显示了timerUpdate()函数崩溃。有人能告诉我我的错误,谢谢。这是我的代码。

bool HelloWorld::init()
{   
    spriteArr = CCArray::create();  
    spriteArr->retain();
}

void HelloWorld::onRestartGame(CCObject* pSender)
{
    CCLog("Restart game");
    _counter = 0;
_scoreLabel->setString(CCString::createWithFormat("%d", _counter)->getCString());

    CCObject* obj;
    CCARRAY_FOREACH(spriteArr, obj) {
        MySprite *sprite = (MySprite *)obj;
        this->removeChild(sprite, true);
    }
        spriteArr->removeAllObjects();
        this->addNewSprite();
        this->schedule(schedule_selector(HelloWorld::gameLogic), 0.1f );
}


void HelloWorld::gameLogic(float dt)
{
    this->timerUpdate();
}

void HelloWorld::addNewSprite()
{
    MySprite *ant = (MySprite *)MySprite::create();
    sprite->addSpriteTo(this);  //Add sprite to scence
    spriteArr->addObject(sprite);
}

void HelloWorld::timerUpdate()
{
     CCObject* obj;
     CCARRAY_FOREACH(spriteArr, obj) {
     MySprite *sprite = (MySprite *)obj;

    int _x = sprite->x + moving_distance*cos(sprite->angle * M_PI/180);
    int _y = sprite->y + moving_distance*sin(sprite->angle * M_PI/180);

    if ((_x <= game_over_left) ||
        (_y <= game_over_bottom) ||
        (_x >= game_over_right) ||
        (_y > game_over_top)) {
        // Game over
        sprite->stopAnimation();
        this->unscheduleAllSelectors();
        // Display game over
        this->onGameOver() ;
        return;
    } else {
        sprite->updatePosition(_x, _y, sprite->angle);
        sprite->setPosition(CCPoint(_x, _y));
    }            
}
this->stopAntatPoint(_fingerPoint);

_counter++;
if (_counter%20 == 0) {
    // Add new sprite
    this->addNewSprite();
}

    _scoreLabel->setString(CCString::createWithFormat("%d", _counter/20 + 1)->getCString());
}

0 个答案:

没有答案