Wednesday, October 23, 2013

Cocos2D-X: Tile Map Layer Empty Gotcha

With Cocos2D-X, if you leave a layer with no tiles, there will be a crash that look like this:


bool CCTexture2D::hasPremultipliedAlpha()
{
   return m_bHasPremultipliedAlpha; <-------- EXC_BAD_ACCESS HERE
}

This is due to the CCTexture2D object being undefined when initialising the layer. This can occur when the layer does not have a tile defined.

It is sometimes necessary to have a layer with no tiles defined initially and then define them in code during runtime. However, due to this crash, it is necessary to define those tiles and remove them in code prior to the game starting. Same problem might happen in Cocos2D also.

No comments:

Post a Comment