Crash using CCTMXTileMap

Hi, I’m porting a project from iPhone/Cocos2d to a cross platform Iphone/Android/Cocos2dx one.

I’m at a very early stage, the only thing the project does at the moment is to load a scene, and in this scene, generates a tilemap with the following code.

@ tileMap = CCTMXTiledMap::tiledMapWithTMXFile(“floor.tmx”);
tileMap~~>setTag;
voidNode~~>addChild(tileMap, 0, ccp(1.0f,1.0f), ccp(~~480,~~320));

int nbChildren = tileMap->getChildren()->count();
for(int i = 0; i < nbChildren; i**){
CCSprite* child = >objectAtIndex);
child
>getTexture->setAntiAliasTexParameters;
}@
However, this code crashs in the CCTMXLayer destructor on the following line
CCTMXLayer::~CCTMXLayer() { CC_SAFE_RELEASE(m_pTileSet); <-- this line
I don’t get what I’m doing wrong. At that point, I’m only allocating objects since it is the initialisation. So I’m guessing I’m doing something wrong with the Children or something, but the same code works fine with cocos2d… so it must be a step I’m missing to make the C** behave the same way.

Any hint on what it could be?

Did you release “tileMap” at some place?

I’m not releasing it anywhere yet.
I usually do that when I’m only working on initialization to avoid problem of that type. :s

I think it is better to paste a sample code that help us to reproduce it.

that’s the .cpp file of my class. Hopefully that will help.
The class TileMapLayer is instantiated once when the scene “HouseScene” is loaded.

`#include “TileMapLayer.h”
#include “AppDelegate.h”
#include “HouseScene.h”

#define kItemMenuWidth 171
#define kItemMenuHeight 68

#define kFakeBkrdOffsetY 40

using namespace cocos2d;

TileMapLayer::TileMapLayer():
avatar(NULL), studioAvatars(NULL), tileMap(NULL), voidNode(NULL), backgroundParalax(NULL), backgroundStudio(NULL),
backgroundStudioFront(NULL), backgroundTower(NULL), backstageArrowMenu(NULL), itemMenu(NULL), moveMenu(NULL),
buyMenu(NULL), interactionStatusLabel(NULL), movingMap(false), zoomingMap(0), playerEnRoute(false),
newWalkWaiting(false), waitingTileCoord(ccp(0,0)), chosenPathNodes(NULL), stageWalking(false), currentContext(0),
activated(false), allowMiniGame(false), currentItem(NULL), currentItemCoord(ccp(0,0)), currentUpperItem(NULL),
onArrivalTask(0), padZoomStatus(0), scrollMaxY(0), scrollMaxX(0), scrollMinX(0), scrollMinY(0)
{

}

TileMapLayer::~TileMapLayer()
{
CCLayer::release();
}

bool TileMapLayer::init()
{
if (!CCLayer::init() )
{
return false;
}

this->setIsTouchEnabled(true);
activated = true;

AppDelegate* myDelegate = (AppDelegate*)CCApplication::sharedApplication;

// Create a void Node, parent Node
voidNode = CCParallaxNode::node();
voidNode->setAnchorPoint(ccp(0.5, 0.5));
voidNode->setPosition(ccp(240, 160));
this->addChild(voidNode, 0);

// If BETTER than LOW spec, show beach bkrd
if (myDelegate->getDeviceSpecGroup() > eDeviceSpec_Low) {
    //Texture Format Setting
    CCTexture2D::setDefaultAlphaPixelFormat(kTexture2DPixelFormat_RGB565);

    //PARALLAX BACKGROUND
    backgroundParalax = CCSprite::spriteWithFile("background_800.png");
    backgroundParalax->setScale(1.2);
    voidNode->addChild(backgroundParalax, 0, ccp(0.2f, 0.2f), ccp(185, 130));
    backgroundParalax->setVertexZ(-1002);

    myDelegate->revertToDefaultPixelFormat();        
}else{
    //PARALLAX BACKGROUND
    backgroundParalax = CCSprite::spriteWithFile("background_3g_city.png", CCRectMake(0, 0, 256*4, 256*4));
    ccTexParams params = {GL_LINEAR,GL_LINEAR,GL_REPEAT,GL_REPEAT};
    backgroundParalax->getTexture()->setTexParameters(&params);
    backgroundParalax->setBlendFunc((ccBlendFunc){GL_ONE,GL_ZERO});

    voidNode->addChild(backgroundParalax, 0, ccp(0.2f, 0.2f), ccp(185, 130));
    backgroundParalax->setVertexZ(-1002);
}

tileMap = CCTMXTiledMap::tiledMapWithTMXFile("MyStar7.tmx");
tileMap->setTag(1);
voidNode->addChild(tileMap, 0, ccp(1.0f,1.0f), ccp(-480,-320));

int nbChildren = tileMap->getChildren()->count();
for(int i = 0; i < nbChildren; i++){
    CCSprite* child = (CCSprite*)(tileMap->getChildren()->objectAtIndex(i));
    child->getTexture()->setAntiAliasTexParameters();
}

// If BETTER than LOW spec, show beach bkrd
if (myDelegate->getDeviceSpecGroup() > eDeviceSpec_Low) {
    //Texture format settings
    CCTexture2D::setDefaultAlphaPixelFormat(kTexture2DPixelFormat_RGB5A1);

    // TOWER BACKGROUND
    backgroundTower = CCSprite::spriteWithFile("background_large_10.png");
    backgroundTower->setAnchorPoint(ccp(0, 0));
    backgroundTower->setPosition(ccp(-13, -90));
    tileMap->addChild(backgroundTower, -1);
    backgroundTower->setVertexZ(-1001);

    //Texture format settings
    myDelegate->revertToDefaultPixelFormat();
}else{
    this->loadBuildingBase3G(6);
}

// Remove the objects entered in Tiled Application
for(int i = 0; i < 7; i++)
    this->setTileInLayer(i, ccp(kTileMapSize-1, kTileMapSize-(i+1)), 0);


return true;

}

void TileMapLayer::loadBuildingBase3G(int size)
{
if (backgroundTower != NULL) {
backgroundTower->removeAllChildrenWithCleanup(true);
tileMap->removeChild(backgroundTower, true);
backgroundTower = NULL;
}

CCLog("Resetting tower with size %d", size);

CCString* tmpString = CCString::stringWithFormat("background_3g_tower_%d.png", size);

backgroundTower = CCSprite::spriteWithFile((const char *)tmpString->toChar(), CCRectMake(0, 0, (80 * (size) + 4), 64 * 6));
backgroundTower->setAnchorPoint(ccp(0, 0));
backgroundTower->setPosition(ccp((40 * (12 - size)) -1, 65 - (size * 25)));

ccTexParams buildingParams = {GL_LINEAR,GL_LINEAR,GL_REPEAT,GL_REPEAT};
backgroundTower->getTexture()->setTexParameters(&buildingParams);
backgroundTower->setBlendFunc((ccBlendFunc){GL_ONE,GL_ZERO});
tileMap->addChild(backgroundTower, -1001);
backgroundTower->setVertexZ(-1001);

}

///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////// TILES ///////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
#pragma mark Tiles

void TileMapLayer::setTileInLayer(int layerId, cocos2d::CCPoint coord, int type)
{
if(layerId < 0)
return;

CCTMXLayer * layer = (CCTMXLayer*)tileMap->getChildByTag(layerId);
//coord = CCDirector::sharedDirector()->convertToGL(coord);
layer->setTileGID(type, coord);

}

void TileMapLayer::setTileInLayer(int layerId, cocos2d::CCPoint coord, int type, cocos2d::ccColor3B colour)
{
if(layerId < 0)
return;

CCTMXLayer * layer = (CCTMXLayer*)tileMap->getChildByTag(layerId);
coord = CCDirector::sharedDirector()->convertToGL(coord);
layer->setTileGID(type, coord);

CCSprite* tileSprite = this->getTileSpriteFromLayer(layerId, coord);
if (tileSprite != NULL) {
    tileSprite->setColor(colour);
}

}

///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////// TILE SPRITES ////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
#pragma mark Tile Sprites

CCSprite * TileMapLayer::getTileSpriteFromLayer(int layerId, CCPoint coord){

if(layerId < 0)
    return NULL;

CCTMXLayer * layer = (CCTMXLayer *)tileMap->getChildByTag(layerId);

// Get openGL coordinate
coord = CCDirector::sharedDirector()->convertToGL(coord);       

// Return sprite from layer
return layer->tileAt(coord);

}`

I have a bit more information,
The error is non-virtual thunk to cocos2d::CCTMXLayer::~CCTMXLayer();

A first quick google search made me find that it’s a problem with the compiler and multiple inheritance.
[[http://lists.apple.com/archives/unix-porting/2003/Dec/msg00107.html]]
If it’s really the case, I’m confused to how solve this issue…

Anyway, if someone does find something wrong with my code, please let me know.