Cocos2d-x 3.7 C++ CCLoad UIPageView 崩溃

Cocos2d-x 3.7 C++ CCLoad UIPageView crashing

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

我一直在使用 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文件中崩溃在下面:

因此,当我尝试通过 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 中修复