an issue about too many level of CCNodes

I found some of my nodes disorderd in my game, and finally I found it is because there are too many level of nodes (the depth of node tree is too large).

add the following codes into HelloWorldScene.cpp(add TestDepth() declaration to .h), and call TestDepth() in init();
if DEPTH <=10, we can see 3 sprites with same size as we expected; (1.png)
but if DEPTH>10, it’s not. (2.png)

int GetNodeDepth(const cocos2d::CCNode *node) {
  cocos2d::CCNode *node2 = const_cast(node);
  int depth=0;
  while( node2 ) {
    depth++;
    node2 = node2->getParent();
  }
  return depth;
}

void HelloWorld::TestDepth() {
  //a scaled container node 
  CCNode *container = CCNode::node();
  container->setScale(2);
  container->setAnchorPoint(ccp(0,0));
  addChild(container);

  // bug occurs if DEPTH >=11
  const int DEPTH = 11;   
  float y = 10;
  for(int i = 0; i < 3; i ++){
    CCSprite *spr = CCSprite::spriteWithFile("CloseNormal.png");
    CCNode *node = spr;
    //recursivley add to empty nodes
    for(int i = 0; i < DEPTH; i ++) {
      CCNode *n = CCNode::node();
      node->setAnchorPoint(ccp(0,0));      
      n->addChild(node);
      node = n;
    }
    //add to container
    container->addChild(node);  
    node->setAnchorPoint(ccp(0,0));
    node->setPosition(ccp(10, y));

    y+=spr->getContentSize().height;
    CCLOG("Sprite Depth: %d", GetNodeDepth(spr));
  }
}

I guess it might because opengl matrix stack size is too small? What’s the default stack size? Can we change it?


1.png (166.9 KB)


2.png (160.6 KB)