A crash at int retVal = UIApplicationMain(argc, argv, nil, @"AppController"); in cocos2dx 2.2.3

1.9k views Asked by At

My code snippet as follow:

void HelloWorld::gameOver()
{
CCDirector *pDirector=CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->removeAllDelegates();

this->stopAllActions();

this->unscheduleUpdate();
this->unscheduleAllSelectors();

CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

auto spriteEndbg1 = CCSprite::create("engbg1136.png");
spriteEndbg1->setPosition(CCPoint(visibleSize.width/2, visibleSize.height/2));
this->addChild(spriteEndbg1, 5);

auto spriteTop = CCSprite::create("gameover.png");
spriteTop->setPosition(CCPoint(visibleSize.width/2, visibleSize.height-200));
this->addChild(spriteTop, 5);

//score
auto scorebg = CCSprite::create("endtextbg.png");
scorebg->setPosition(CCPoint(visibleSize.width/2, visibleSize.height-350));
this->addChild(scorebg, 5);
char *str = new char(5);
sprintf(str, "您的得分为:%d", scodeNum);
std::string strScore = str;
CCLabelTTF* pLabel = CCLabelTTF::create(str, "Arial", 50);
pLabel->setPosition(ccp(origin.x + visibleSize.width/2,
                        origin.y + visibleSize.height - pLabel->getContentSize().height));
this->addChild(pLabel, 5);

//try again
auto tyrAgainbg = CCSprite::create("endtextbg.png");
tyrAgainbg->setPosition(CCPoint(visibleSize.width/2, 300));
this->addChild(tyrAgainbg, 5);
CCMenuItemFont::setFontName("American Typewriter");
CCMenuItemFont::setFontSize(60);
auto closeItem = CCMenuItemFont::create("ReStart", this,
                                        menu_selector(HelloWorld::restartFn));

closeItem->setPosition(CCPoint(visibleSize.width/2, 300));
auto menu = CCMenu::create(closeItem,NULL);
menu->setPosition(ccp(0,0));
this->addChild(menu, 5);
}

When my project after run this function a crash appear at

int retVal = UIApplicationMain(argc, argv, nil, @"AppController");

It is strange that argv is null.

The stack information shown at follow:

enter image description here

Anyone has encounter this kind of question?

1

There are 1 answers

0
Cerniuk On

From the example in the question I can't say for sure but in my case it was a partial refactoring of an IBOutlet instance variable name change.

IChanging IBOutlet variable names using Xcode refactoring tools can easily cause your app to get an NSAssert / NSException (aka crash) at UIApplicationMain()...

Xcode fails to rename the outlet property in the refactor -> rename... This means you have to manually open up the .xib files where that instance variable is referenced and hand-change the names there too.

For a full visual example, see this thread and my answer in: Changing IBOutlet Variable Names and Crashing at UIApplicationMain ()