gpt4 book ai didi

c++ - Cocos2d-x 3.7 C++ CCLoad UIPageView 崩溃

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:13:54 25 4
gpt4 key购买 nike

这发生在所有平台上,但此描述适用于通过 Xcode 的 iPhone 5s 8.4 模拟器。

我一直在使用 C++ 和 cocos2d-x 3.6 版以及 Cocostudio 2.3.1 开发游戏。一切都很好,直到我更新到 cocos 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
//....

}

Sooo.... 事情发生在 mainPageView 上。崩溃发生在我从设计文件中引用 UIPageView 并将其分配给 mainPageView ivar 的行。 Crash不说什么,而是在NavMesh文件中崩溃在下面:

enter image description here

因此,当我尝试通过 pushscene 从 mainMenu 切换到该场景时,它崩溃了。还有一件事......如果我在 init() 方法中使用局部变量,如:auto mainPageView 而不是 ivar,它不会崩溃。如果我评论 UIPageView 引用,例如崩溃线 - 它不会崩溃。

我尝试过的:将 Cocostudio 更新到最新的 2.3.1.1。使用该新版本重新发布了所有 UI。清理了构建的所有缓存和内容。通过使用新版本创建新项目并将旧版本的文件复制并导入到项目中来更新到新的 cocos 引擎版本。这只是说我已经尝试了几种方法。

如有任何帮助,我们将不胜感激。我确信这可能是我犯的一个愚蠢的错误...

干杯!

最佳答案

我认为你触发了这个错误: https://github.com/cocos2d/cocos2d-x/issues/12962

它将在 v3.7.1 中修复

关于c++ - Cocos2d-x 3.7 C++ CCLoad UIPageView 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31610456/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com