CCTMXTiledMap - crash on loading tileset

Hello,

I am using CCTMXTiledMap to load level.tmx file on android platform, using cocos2dx:

CCTMXTiledMap * map = CCTMXTiledMap::tiledMapWithTMXFile("worlds/A/1/level.tmx");

My Resources dir contains folders worlds and images.

Beginning of my level.tmx file looks like this:

When I execute the level loading code, I get the popup:
“Get data from file(assets/worlds/A/1/…/…/…/images/img_test.png) failed!”.

I did some research and found out that in cocos2dx/platform/CCFileUtils.cpp (line 318) there is a call to zlib method:
int nRet = unzLocateFile(pFile, pszFileName, 1);
which probably cannot handle the “…/…/…” sings in the path. I fixed this in the cocos2dx/platform/android/CCFileUtils_android.cpp file by adding this code to simplify the path by stripping … characters:

std::string path = fullPath;        
std::string firstPart, secondPart;
std::string pattern("/..");
size_t index;
while((index = path.find(pattern)) != std::string::npos){
    firstPart = path.substr(0, index);
    firstPart = firstPart.substr(0, firstPart.find_last_of("/"));       
    secondPart = path.substr(index + pattern.length());
    path = firstPart + secondPart;
}       
fullPath = path;

Maybe it is not super-optimal, but it works :slight_smile: I added it in the line 79, after the fullPath.insert(0, "assets/"); call in getFileData method.

Hope someone will find this useful! :slight_smile:

Regards,
km