今天看了下
利用cocos2dx 3.2开发消灭星星
http://blog.youkuaiyun.com/hezijian22/article/details/39137487一系列教程,感觉很好,于是就下载了源码,自己编译运行下。
今天在运行消灭星星时,在win32上没问题,但是在android平台下,总是出现下面
这个错误:
04-10 18:11:40.926: D/dalvikvm(18100): Trying to load lib /data/data/com.smart.star/lib/libcocos2dcpp.so 0x3195d750
04-10 18:11:40.926: D/cocos2d-x debug info(18100): cocos2d: fullPathForFilename: No file found at ChineseWords.xml. Possible missing file.
04-10 18:11:40.946: A/libc(18100): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1)
代码如下:
#ifndef _CHINESEWORD_H_
#define _CHINESEWORD_H_
#include <string>
#include <cocos2d.h>
using namespace std;
using namespace cocos2d;
static ValueVector txt_vec = FileUtils::getInstance()->getValueVectorFromFile("ChineseWords.xml");
static string file = FileUtils::getInstance()->fullPathForFilename("menu_start.png");
string ChineseWord(const char* wordId);
#endif
我做了一下测试:
1、修改ChineseWords.xml名字,不行。
2、在资源文件目录下找一张图片,如menu_start.png,然后放在同样的位置
使用FileUtils::getInstance()->fullPathForFilename("menu_start.png");这个函数,同样报错。
从这里应该就能看出,static ValueVector txt_vec = FileUtils::getInstance()->getValueVectorFromFile("ChineseWords.xml");
上面的代码放在这里执行在android下不可以。
解决:
我们定义一个全局的ValueVector txt_vec变量,不在这里初始化,而放在GameLayer.cpp的init函数中
调用txt_vec = FileUtils::getInstance()->getValueVectorFromFile("ChineseWords.xml");,问题就解决了。