TMX Loading, CCAssert on texture != NULL

Hi all

I must say I’m enjoying Cocos2d-x thoroughly but I appear to have hit a stumbling point while following various examples of trying to load a TMX. I’ve come across an issue whereby Cocos2d-x seems to differ in behaviour from Cocos2d.

The problems start at around the following area:

bool CCTMXLayer::initWithTilesetInfo(CCTMXTilesetInfo *tilesetInfo, CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo)

tilesetInfo is NULL which in turn leads CCTexture2D *texture to be null. This is the same behaviour for the usage in both Cocos2d-x and Cocos2d.

CCTexture2D *texture = NULL;
if( tilesetInfo )
{
    texture = CCTextureCache::sharedTextureCache()->addImage(tilesetInfo->m_sSourceImage.c_str());
}

if (CCSpriteBatchNode::initWithTexture(texture, (unsigned int)capacity)) // !!!
{
...
}

CCSpriteBatchNode::initWithTexture in turn calls CCTextureAtlas::initWithTexture as you can see below:

    bool CCSpriteBatchNode::initWithTexture(CCTexture2D *tex, unsigned int capacity)
    {
        m_blendFunc.src = CC_BLEND_SRC;
        m_blendFunc.dst = CC_BLEND_DST;
        m_pobTextureAtlas = new CCTextureAtlas();
        m_pobTextureAtlas->initWithTexture(tex, capacity); // !!!

        ...

    }

Object tex is NULL at this point in both versions of the framework. The difference is in the of the CCAssert in the Cocos2d-x version of CCTextureAtlas which basically halts all progress.

For example:

Cocos2d-x:

bool CCTextureAtlas::initWithTexture(CCTexture2D *texture, unsigned int capacity)
{
*   CCAssert(texture != NULL, "texture should not be null"); // !!!*
    m_uCapacity = capacity;
    m_uTotalQuads = 0;

Cocos2d:

-(id) initWithTexture:(CCTexture2D*)tex capacity:(NSUInteger)n
{
    if( (self=[super init]) ) {

        capacity_ = n;
        totalQuads_ = 0;

I’ve looked on the forums and online for information on this but I am unable to find anything. Is this a known problem?

I would really appreciate any help on the matter :slight_smile:

Thanks!

Think I see this when I have a layer that is empty, try deleting the empty layer or adding a tile to that layer.

Arrgh, that was the problem! thank you :slight_smile:

Yeah, would be good if that assert got changed to a warning. It gave me problems when I started with TMX maps too.

Yeah, would be good if that assert got changed to a warning. It gave me problems when I started with TMX maps too.

Definitely agreed that it needs to be a little more intuitive.

Thanks again btw!