The cocos2d sample loader uses b2dJson::readFromFile() to load the RUBE json scene. I based my cocos2d-x project off this sample and everything worked fine to begin building/running on linux, but crashes on Android.
When running the app on Android, it was unable to read the file, even though the path was correct and the permissions on the file were world readable. The simple fix is to use cocos2d-x FileUtils to load the data and pass the string to b2dJson:
e.g) instead of
Code: Select all
world = json.readFromFile(fullPath, errMsg);
Code: Select all
unsigned long fileSize = 0;
unsigned char* fileData = NULL;
fileData = FileUtils::getInstance()->getFileData(fullPath, "r", &fileSize);
std::string jsonContent;
jsonContent.assign(reinterpret_cast<const char*>(fileData), fileSize);
world = json.readFromString(jsonContent, errMsg);