Nikolay Lastname Bad access in CCSprite::addChild
Posts 12
Added by Nikolay Lastname about 1 year ago

I am trying to add black backgound with opacity to my sprite (something like LIghtbox):
CCLayerColor *blackBg = CCLayerColor::layerWithColor(ccc4(0, 0, 0, 100));
this->addChild(blackBg,blackBgZOrder);
And I get EXC_BAD_ACCESS when adding it to "this". "this" is not NULL, and blackBg too.

void CCSprite::addChild(CCNode *pChild, int zOrder, int tag) {
CCAssert(pChild != NULL, "");
CCNode::addChild(pChild, zOrder, tag);

if (m_bUsesBatchNode)
{
CCAssert(((CCSprite*)pChild)->getTexture()->getName() == m_pobTextureAtlas->getTexture()->getName(), "");// Here is the line where I get EXC_BAD_ACCESS
unsigned int index = m_pobBatchNode->atlasIndexForChild((CCSprite*)(pChild), zOrder);
m_pobBatchNode->insertChild((CCSprite*)(pChild), index);
}

Can anyone explain what this line means?

Kevin H RE: Bad access in CCSprite::addChild
Posts 70
Added by Kevin H about 1 year ago

Since its going into the "if(m_bUsesBatchNode)" section, the sprite is setup to use a sprite batch node. If the sprite is using a sprite batch node, it must use the same texture as the parent node.

Nikolay Lastname RE: Bad access in CCSprite::addChild
Posts 12
Added by Nikolay Lastname about 1 year ago

it must use the same texture as the parent node.

But I use CCLayerColor. There is no any textures


(1-2/2)