Cocos2d-x Android项目随机崩溃libc致命信号11错误?

时间:2014-10-27 02:46:04

标签: android c++ android-ndk cocos2d-x cocos2d-x-2.x

我正在使用Cocos2d-x来构建Win32和Android应用程序。但是当我尝试从Win32移植到Android时,我遇到了一个致命的问题。我在Android中编写了以下代码,尝试从资产中读取文件。但是,每次Android应用程序在CCFileUtils::sharedFileUtils()->getFileData崩溃时。我不知道为什么。我在其他地方使用此代码,它们都可以正常工作。

#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
    unsigned long size = 0;
    CCLog("filepath name %s",filename);
    unsigned char* filebuff = CCFileUtils::sharedFileUtils()->getFileData(filename,"rb",&size);
    CCLog("filebuff");
    CCString* ccStr = CCString::createWithData(filebuff,size);
    CCLog("ccstr end");
    RunScriptBuffer(ccStr->getCString(),ret_string,name);
#endif

这是整个功能实现:

bool CLuaScriptReader::RunScriptFile(const char *filename,char* ret_string,char *name){
    if( m_plua == NULL || ret_string == NULL || filename == NULL ) return false;
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
    char filebuff[MAX_LUA_FILE_LEN] = "";
    char line[1024] = "";
    FILE* fpFile = fopen(filename,"r");
    if( fpFile == NULL ) {
        printf("can not find file %s\n",filename);
        return false;
    }
    while( fgets(line, 1024, fpFile) != NULL) {
        strcat(filebuff,line);
    }
    fclose(fpFile);
    RunScriptBuffer(filebuff,ret_string,name);
#endif
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
    unsigned long size = 0;
    CCLog("filepath name %s",filename);
    unsigned char* filebuff = CCFileUtils::sharedFileUtils()->getFileData(filename,"rb",&size);
    CCLog("filebuff %l",size);
    CCString* ccStr = CCString::createWithData(filebuff,size);
    CCLog("ccstr end");
    RunScriptBuffer(ccStr->getCString(),ret_string,name);
#endif
    return true;
}

以下是我使用ndk-stack工具获得的错误日志。

********** Crash dump: **********
Build fingerprint: 'google/yakju/maguro:4.3/JWR66Y/776638:user/release-keys'
pid: 20518, tid: 20541, name: Thread-61225  >>> com.einverne.test_py <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr e72d2d24
Stack frame #00  pc 00010354  /system/lib/libc.so (dlmalloc+1207): Unable to ope
n symbol file d:\graduation_project\cocos2d-x-2.1.5\projects\Test_py\proj.androi
d\obj\local\armeabi\/libc.so. Error (9): Bad file descriptor
Stack frame #01  pc 0000dcc7  /system/lib/libc.so (malloc+10): Unable to open sy
mbol file d:\graduation_project\cocos2d-x-2.1.5\projects\Test_py\proj.android\ob
j\local\armeabi\/libc.so. Error (9): Bad file descriptor
Stack frame #02  pc 0000aa98  /system/lib/libz.so (inflateInit2_+100)
Stack frame #03  pc 00523044  /data/app-lib/com.einverne.test_py-2/libcocos2dcpp
.so (cocos2d::unzOpenCurrentFile3(void*, int*, int*, int, char const*)+836): Rou
tine unzOpenCurrentFile3 in D:\graduation_project\cocos2d-x-2.1.5/cocos2dx/suppo
rt/zip_support/unzip.cpp:1618
Stack frame #04  pc 00523138  /data/app-lib/com.einverne.test_py-2/libcocos2dcpp
.so (cocos2d::unzOpenCurrentFile(void*)+40): Routine unzOpenCurrentFile in D:\gr
aduation_project\cocos2d-x-2.1.5/cocos2dx/support/zip_support/unzip.cpp:1677
Stack frame #05  pc 0051d318  /data/app-lib/com.einverne.test_py-2/libcocos2dcpp
.so (cocos2d::ZipFile::getFileData(std::string const&, unsigned long*)+360): Rou
tine getFileData in D:\graduation_project\cocos2d-x-2.1.5/cocos2dx/support/zip_s
upport/ZipUtils.cpp:561
Stack frame #06  pc 004ef98c  /data/app-lib/com.einverne.test_py-2/libcocos2dcpp
.so (cocos2d::CCFileUtilsAndroid::getFileData(char const*, char const*, unsigned
 long*)+252): Routine getFileData in D:\graduation_project\cocos2d-x-2.1.5/cocos
2dx/platform/android/CCFileUtilsAndroid.cpp:134
Stack frame #07  pc 00243ab4  /data/app-lib/com.einverne.test_py-2/libcocos2dcpp
.so (CLuaScriptReader::RunScriptFile(char const*, char*, char*)+152): Routine Ru
nScriptFile in jni/../../Classes/LuaScriptReader.cpp:330
Stack frame #08  pc 0023e704  /data/app-lib/com.einverne.test_py-2/libcocos2dcpp
.so (JudgeManager::getResult(std::string, std::string, std::string, CharacterExt
end*, std::string)+1004): Routine getResult in jni/../../Classes/JudgeManager.cp
p:87

编辑:在Android Logcat中,我收到Fatal signal 11 (SIGSEGV) at 0xe72d2d24 (code=1), thread 26592 (Thread-61675)错误。

0 个答案:

没有答案