我把CocoGUILIB例子里的UI文件更换成自己的,会引起程序崩溃

我把CocoGUILIB例子里的UI文件更换成自己的,总是会会引起程序崩溃,请问大家有没有遇到过呀, 这时bug吗。
我是正常使用cocostudioUi编辑器导出的三个文件test.json test0.plist test0.png, 并没有什么特殊之处。

有时幸运就能导出能使用的文件,程序不崩溃,有时又不行。 但基本是不行的居多。

提示:
“test.win32.exe中的0x0fd69b46(libcocos2d.dll)处有未经处理的异常:
0xC0000005:读取位置0x00000018时发生冲突”

原因是你没有设置资源路径
解决办法:
在AppDelegate.cpp 的 bool AppDelegate::applicationDidFinishLaunching() 函数中,加入设置资源路径的代码:
std::vectorstd::string searchPath;
searchPath.push_back(“UIRES”);
CCFileUtils::sharedFileUtils()->setSearchPaths(searchPath);

注意,这三行代码必须加在 CCScene *pScene = HelloWorld::scene(); 这句之前
PS:我这里指定的路径是UIRES,就是官方例子放置UI资源的地方,你应该填在你放置XXX.plist与xxx.jason的位置

:dizzy:最后怎么解决的?我的恶业这样~楼上的方法试了没用

这论坛貌似不能上传图片和附件。。。。我这边也不行。。。

— Begin quote from ____

%url%wcw 发表于 2013-5-18 15:53
你上传吧,我可以试试,vs下面的

— End quote

在哪里上传,没看到上传的按钮,谢谢你。

— Begin quote from ____

%url%soulit 发表于 2013-5-18 15:07
有谁愿意吗,我上传我导出的UI给你们试试!
是不是我的机器有问题!
我的是64bit win7系统

— End quote

你上传吧,我可以试试,vs下面的

我发现我导出的json文件和例子中的CocoGUISample.json不是一样的结构的,对不上呢。

我是我导出的test.json:
{“classname”:null,“name”:null,“designHeight”:320,“designWidth”:480,“textures”:“test0.plist”],“version”:1,“widgetTree”:{“classname”:“Panel”,“name”:null,“children”:{“classname”:“Panel”,“name”:null,“children”:],“options”:{"__type":“ComGUIPanelSurrogate:#SPEditorCommon.JsonModel.Component.GUI”,“classname”:“Panel”,“name”:“default”,“ZOrder”:0,“classType”:“Panel”,“colorB”:255,“colorG”:200,“colorR”:150,“flipX”:false,“flipY”:false,“height”:320,“opacity”:100,“rotation”:0,“scaleX”:1,“scaleY”:1,“touchAble”:false,“useMergedTexture”:true,“visible”:true,“width”:480,“x”:1,“xProportion”:1,“y”:0,“yProportion”:0,“backGroundImage”:null,“clipAble”:false}},{“classname”:“Button”,“name”:null,“children”:],“options”:{"__type":“ComGUIButtonSurrogate:#SPEditorCommon.JsonModel.Component.GUI”,“classname”:“Button”,“name”:“btn”,“ZOrder”:1,“classType”:“Button”,“colorB”:255,“colorG”:255,“colorR”:255,“flipX”:false,“flipY”:false,“height”:30,“opacity”:255,“rotation”:0,“scaleX”:1,“scaleY”:1,“touchAble”:true,“useMergedTexture”:true,“visible”:true,“width”:100,“x”:216,“xProportion”:216,“y”:167,“yProportion”:167,“disabled”:"",“normal”:“backtotopnormal.png”,“pressed”:“backtotoppressed.png”}}],“options”:{"__type":“ComGUIPanelSurrogate:#SPEditorCommon.JsonModel.Component.GUI”,“classname”:“Panel”,“name”:“default”,“ZOrder”:1,“classType”:“Panel”,“colorB”:255,“colorG”:200,“colorR”:150,“flipX”:false,“flipY”:false,“height”:0,“opacity”:100,“rotation”:0,“scaleX”:1,“scaleY”:1,“touchAble”:true,“useMergedTexture”:true,“visible”:true,“width”:0,“x”:0,“xProportion”:0,“y”:0,“yProportion”:0,“backGroundImage”:null,“clipAble”:false}}}

— Begin quote from ____

%url%wcw 发表于 2013-5-18 14:36
代码是不是需要修改啊:

— End quote

您好,我就是像你这么修改的。
但还是崩溃,要么是断言有问题:
“ Expression: pSpriteFrame != 0"

这看起来像是创建sprite没成功。。。如果想深究是什么问题,可以在断言那里断个点看看

— Begin quote from ____

%url%wcw 发表于 2013-5-18 14:57
这看起来像是创建sprite没成功。。。如果想深究是什么问题,可以在断言那里断个点看看 …

— End quote

有谁愿意吗,我上传我导出的UI给你们试试!
是不是我的机器有问题!
我的是64bit win7系统
cocostuio版本v0.0.1.1

— Begin quote from ____

%url%soulit 发表于 2013-5-18 15:07
有谁愿意吗,我上传我导出的UI给你们试试!
是不是我的机器有问题!
我的是64bit win7系统

— End quote

void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist)
{
    CCAssert(pszPlist, "plist filename should not be NULL");

    if (m_pLoadedFileNames->find(pszPlist) == m_pLoadedFileNames->end())
    {
        std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszPlist);
        CCDictionary *dict = CCDictionary::createWithContentsOfFileThreadSafe(fullPath.c_str());

是执行到这里时, dict 为空指针

代码是不是需要修改啊:

bool HelloWorld::init()
{
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    COCOUISYSTEM->resetSystem(this);
    
    COCOUISYSTEM->replaceUISceneWithFile(this, "test.json", 1, true,true,true);
    /*
    cs::CocoScrollView* sc = (cs::CocoScrollView*)(COCOUISYSTEM->getWidgetByName("scrollview"));
    sc->setUpdateEnable(true);
    cs::CocoTextButton* bt = (cs::CocoTextButton*)(COCOUISYSTEM->getWidgetByName("backtotopbutton"));
    bt->addReleaseEvent(this, coco_releaseselector(HelloWorld::backToTop));
    cs::CocoSlider* sld = (cs::CocoSlider*)(COCOUISYSTEM->getWidgetByName("slider"));
    sld->addPercentChangedEvent(this, coco_percentchangedselector(HelloWorld::sliderPercentChanged));
    cs::CocoButton* anib = (cs::CocoButton*)(COCOUISYSTEM->getWidgetByName("animationbutton"));
    anib->addReleaseEvent(this, coco_releaseselector(HelloWorld::playUIAnimation));
    cs::CocoButton* exit = (cs::CocoButton*)(COCOUISYSTEM->getWidgetByName("exitbutton"));
    exit->addReleaseEvent(this, coco_releaseselector(HelloWorld::menuCloseCallback));
    exit->addCancelEvent(this, coco_cancelselector(HelloWorld::cancelTouch));
	*/
    return true;
}

:dizzy:
怎么解决这个问题撒!

原因是你没有设置资源路径
解决办法:
在AppDelegate.cpp 的 bool AppDelegate::applicationDidFinishLaunching() 函数中,加入设置资源路径的代码:
std::vectorstd::string searchPath;
searchPath.push_back(“UIRES”);
CCFileUtils::sharedFileUtils()->setSearchPaths(searchPath);

注意,这三行代码必须加在 CCScene *pScene = HelloWorld::scene(); 这句之前
PS:我这里指定的路径是UIRES,就是官方例子放置UI资源的地方,你应该填在你放置XXX.plist与xxx.jason的位置

这论坛貌似不能上传图片和附件。。。。我这边也不行。。。

— Begin quote from ____

%url%soulit 发表于 2013-5-18 15:07
有谁愿意吗,我上传我导出的UI给你们试试!
是不是我的机器有问题!
我的是64bit win7系统

— End quote

你上传吧,我可以试试,vs下面的

这看起来像是创建sprite没成功。。。如果想深究是什么问题,可以在断言那里断个点看看

代码是不是需要修改啊:

bool HelloWorld::init()
{
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    COCOUISYSTEM->resetSystem(this);
    
    COCOUISYSTEM->replaceUISceneWithFile(this, "test.json", 1, true,true,true);
    /*
    cs::CocoScrollView* sc = (cs::CocoScrollView*)(COCOUISYSTEM->getWidgetByName("scrollview"));
    sc->setUpdateEnable(true);
    cs::CocoTextButton* bt = (cs::CocoTextButton*)(COCOUISYSTEM->getWidgetByName("backtotopbutton"));
    bt->addReleaseEvent(this, coco_releaseselector(HelloWorld::backToTop));
    cs::CocoSlider* sld = (cs::CocoSlider*)(COCOUISYSTEM->getWidgetByName("slider"));
    sld->addPercentChangedEvent(this, coco_percentchangedselector(HelloWorld::sliderPercentChanged));
    cs::CocoButton* anib = (cs::CocoButton*)(COCOUISYSTEM->getWidgetByName("animationbutton"));
    anib->addReleaseEvent(this, coco_releaseselector(HelloWorld::playUIAnimation));
    cs::CocoButton* exit = (cs::CocoButton*)(COCOUISYSTEM->getWidgetByName("exitbutton"));
    exit->addReleaseEvent(this, coco_releaseselector(HelloWorld::menuCloseCallback));
    exit->addCancelEvent(this, coco_cancelselector(HelloWorld::cancelTouch));
	*/
    return true;
}