1

I'm on my way with porting SneakyInput Joystick lib to Cocos2d-x and I've basically managed to finish this work, but sometimes I'm getting strange CCAssert error:

CCNode::void CCSprite::addChild(CCNode *pChild, int zOrder, int tag)
{
 // ...
 CCAssert( pChildSprite, "CCSprite only supports CCSprites as children when using CCSpriteBatchNode"); // SIGABRT here
 // ...
}

On my side calling of CCNode's 'addChild' method happening here:

void SneakyButtonSkinnedBase::setButton(SneakyButton *pButton)
{
 if (button) {
    if (button->getParent()) {
        button->getParent()->removeChild(button, true); 
    }
    button->release();
 }

 pButton->retain();
 button = pButton;

 if (pButton) {
     this->addChild(button, 4); /* !!! crash here !!! */
     if (defaultSprite) {
         button->setRadius(defaultSprite->boundingBox().size.width/2);
     }
 }

/* Original iOS code */     

//    if(button){
//      if(button.parent)
//          [button.parent removeChild:button cleanup:YES];
//      [button release];
//  }
//  button = [aButton retain];
//  if(aButton){
//      [self addChild:button z:4];
//      if(defaultSprite)
//          [button setRadius:defaultSprite.contentSize.width/2];
//  }
}

I have absolutely no idea what happening: I have no any references to BatchNode class in my project (and in library too). Moreover, error appearing randomly (~7-8 times from 10 attempts). I wonder - it is a hided logic of framework? It performs some conversion when I'm trying to add several similar sprites to the layer (four navigation buttons)? So why does it work on cocos2-d without errors in this case?

4

0 回答 0