I'm having problems creating a tmx map from string input.
bool LevelManager::initLevel(int currentLevel) { const char* map; try { map = LevelManager::getLevel(currentLevel); } catch (int) { throw 1; } if(map != NULL){ CCLog("%s", map); tileMap = CCTMXTiledMap::create(map); tileMap->setAnchorPoint(ccp(0,0)); tileMap->setPosition(ccp(15,20)); this->addChild(tileMap, 5); backgoundLayer = tileMap->layerNamed("Background"); } else { throw 1; } return true; }
Thats my code. It is very unstable. Most of the times it crashes and sometimes it doesn't. I'm loading my map from the string map. Wich is a const *char. My map is named Level1.tmx and when i load the map like this: tileMap = CCTMXTiledMap::create("Level1.tmx"); it always works and never crashes. And i know for a fact that the value of map is Level1.tmx because i log it in the line before the load.
When it crashes the log outputs this: (lldb) and on the line tileMap->setAnchorPoint(ccp(0,0)); it says "Thread 1: EXC_BAD_ACCESS (code=2, adress=0x0)
Does anyone know why this happens and how to fix it?
Many thanks.
Ps: i'm using xcode, the latest cocos2d-x release and the iPhone simulator
Edit:
Using breakpoints i checked where things go bad while loading the tilemap.
on the line tileMap = CCTMXTiledMap::create(map); my variable map is still fine
but on line tileMap->setAnchorPoint(ccp(0,0)); it is suddenly corrupted (most of the time)