【问题标题】:Cocos2d-x 3.7 C++ CCLoad UIPageView crashingCocos2d-x 3.7 C++ CCLoad UIPageView 崩溃
【发布时间】:2015-07-24 12:22:27
【问题描述】:

这发生在所有平台上,但此描述适用于 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 引擎版本。这只是说我尝试了几件事。

任何帮助将不胜感激。而且我确信这可能是我的一个愚蠢的错误......

干杯!

【问题讨论】:

    标签: c++ ios crash cocos2d-x cocos2d-x-3.0


    【解决方案1】:

    我认为您正在触发此错误: https://github.com/cocos2d/cocos2d-x/issues/12962

    它将在 v3.7.1 中修复

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-28
      • 1970-01-01
      • 1970-01-01
      • 2011-07-04
      相关资源
      最近更新 更多