fix: not crash if CC_SPRITE_DEBUG_DRAW is enabled in SpriteBatchNode

`SpriteBatchNode` was trying to render `DrawNode` when
`CC_SPRITE_DEBUG_DRAW` was enabled.

Github issue #14730
This commit is contained in:
Ricardo Quesada 2016-06-20 19:13:53 -07:00
parent c25550e1a4
commit ca677f2be1
1 changed files with 12 additions and 0 deletions

View File

@ -544,6 +544,18 @@ void SpriteBatchNode::appendChild(Sprite* sprite)
// add children recursively
auto& children = sprite->getChildren();
for(const auto &child: children) {
#if CC_SPRITE_DEBUG_DRAW
// when using CC_SPRITE_DEBUG_DRAW, a DrawNode is appended to sprites. remove it since only Sprites can be used
// as children in SpriteBatchNode
// Github issue #14730
if (dynamic_cast<DrawNode*>(child)) {
// to avoid calling Sprite::removeChild()
sprite->Node::removeChild(child, true);
}
else
#else
CCASSERT(dynamic_cast<Sprite*>(child) != nullptr, "You can only add Sprites (or subclass of Sprite) to SpriteBatchNode");
#endif
appendChild(static_cast<Sprite*>(child));
}
}