0

我的代码片段如下:

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);
}

当我的项目运行此功能后出现崩溃

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

奇怪的是 argv 为空。

堆栈信息如下所示:

在此处输入图像描述

有人遇到过这种问题吗?

4

1 回答 1

0

从问题中的示例中,我不能肯定地说,但在我的情况下,它是对IBOutlet实例变量名称更改的部分重构。

NSAssert使用 Xcode 重构工具更改IBOutlet变量名称很容易导致您的应用程序NSExceptionUIApplicationMain()...

Xcode 无法outlet property在重构中重命名 -> rename... 这意味着您必须手动打开引用该实例变量的 .xib 文件,并在那里手动更改名称。

有关完整的视觉示例,请参阅此线程和我的答案: 更改 IBOutlet 变量名称并在 UIApplicationMain () 处崩溃

于 2017-09-25T00:49:15.987 回答