这在所有平台上都会发生,但是这种描述是通过Xcode对iPhone 5s8.4模拟器进行的。
我一直在使用C++和cocos2d-x版本3.6和Cocostudio 2.3.1开发这个游戏。一切都很好,直到我更新到可可3.7的官方释放。应用程序开始出现崩溃。其中一个是关于UIPageView的特别有趣的。所以我的头文件和cpp文件是这样的:
MKEpochSelectionScene.h
#include "cocos2d.h"
#include "cocos-ext.h"
#include <cocos/ui/CocosGUI.h>
class MKEpochSelectionScene : public cocos2d::Scene {
public:
bool init();
CREATE_FUNC(MKEpochSelectionScene);
private:
cocos2d::ui::PageView * mainPageView;
void previousEpoch(Ref* pSender, cocos2d::ui::Widget::TouchEventType eEventType);
void nextEpoch(Ref* pSender, cocos2d::ui::Widget::TouchEventType eEventType);
void showEpoch(Ref* pSender, cocos2d::ui::Widget::TouchEventType eEventType);
};MKEpochSelectionScene.cpp
#include "MKEpochSelectionScene.h"
#include <editor-support/cocostudio/CocoStudio.h>
#include "MKGameScene.h"
#include "MKLevelSelectionScene.h"
USING_NS_CC;
bool MKEpochSelectionScene::init()
{
if(!Scene::init()) return false;
auto node = CSLoader::createNode("UI/Epoch/Layer.csb");
this->addChild(node);
auto buttonLeft = node->getChildByName<ui::Button *>("Button_Left");
CCASSERT(buttonLeft != nullptr, "Button left is null");
buttonLeft->addTouchEventListener(CC_CALLBACK_2(MKEpochSelectionScene::nextEpoch,this));
auto buttonRight = node->getChildByName<ui::Button *>("Button_Right");
CCASSERT(buttonRight != nullptr, "Button right is null");
buttonRight->addTouchEventListener(CC_CALLBACK_2(MKEpochSelectionScene::previousEpoch,this));
//******CRASHING LINE
mainPageView = (cocos2d::ui::PageView *)node->getChildByName("selectEpoch");
//******CRASHING LINE
CCASSERT(mainPageView != nullptr, "Main pageview is nil");
CCASSERT(mainPageView->getPages().size() > 0, "Page view has zero pages");
return true;
}
//Other methods
//....
}所以..。这种情况发生在mainPageView上。崩溃发生在我从设计文件中引用UIPageView并将其分配给mainPageView ivar的行中。崩溃没有说什么,而是在以下NavMesh文件中崩溃:

所以当我试图按下场景从mainMenu切换到这个场景时,它就崩溃了。还有一件事。如果我在init()方法中使用局部变量,如:而不是ivar,它不会崩溃。如果我评论UIPageView引用,例如崩溃线-它不会崩溃。
我尝试过的是:将Cocostudio更新为2.3.1.1,这是最新的。使用该新版本重新发布所有UI。清理了建筑的所有储藏物和东西。通过使用新版本创建新项目并从旧版本复制文件并导入到项目中,对新的cocos引擎版本进行更新。这只是说我试过几件事。
任何帮助都将不胜感激。我相信这可能是我的愚蠢错误..。
干杯!
发布于 2015-07-29 18:07:15
我认为你触发了这个bug:https://github.com/cocos2d/cocos2d-x/issues/12962
它将在3.7.1版本中得到修正。
https://stackoverflow.com/questions/31610456
复制相似问题