I have a CCNode based class. If I do the following it works, but if I do the second approach where it is a CCSprite based class it crashes in addChild().
// Note: I have stripped out everything except the parts pertaining to the issue
// Approach 1 - This works
class CMyClass : public CCNode
{
protected:
CCRenderTexture m_texture;
public:
bool initWithWidthAndHeight( int nWidth, int nHeight )
{
addChild( &m_texture);
m_texture.initWithWidthAndHeight( m_nWidth, m_nHeight );
return true;
}
static CMyClass *createWithWidthAndHeight( int nWidth, int nHeight );
};
// Approach 2 - This crashes in addChild()
class CMyClass : public CCSprite
{
protected:
CCRenderTexture *m_pTexture;
public:
CMyClass()
{
m_pTexture = NULL;
}
bool initWithWidthAndHeight( int nWidth, int nHeight )
{
m_pTexture = CCRenderTexture::renderTextureWithWidthAndHeight( nWidth, nHeight );
addChild( m_pTexture ); // CRASH!
}
static CMyClass *createWithWidthAndHeight( int nWidth, int nHeight );
};
// Common to both versions
CMyClass *CMyClass::createWithWidthAndHeight( int nWidth, int nHeight )
{
CMyClass *pobSprite = new CMyClass();
if ( pobSprite && pobSprite->initWithWidthAndHeight( nWidth, nHeight ) )
{
pobSprite->autorelease();
return pobSprite;
}
CC_SAFE_DELETE( pobSprite );
return NULL;
}
I have verified that m_pTexture is a valid object.
Any ideas?