mirror of https://github.com/axmolengine/axmol.git
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:
parent
c25550e1a4
commit
ca677f2be1
|
@ -544,6 +544,18 @@ void SpriteBatchNode::appendChild(Sprite* sprite)
|
||||||
// add children recursively
|
// add children recursively
|
||||||
auto& children = sprite->getChildren();
|
auto& children = sprite->getChildren();
|
||||||
for(const auto &child: children) {
|
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));
|
appendChild(static_cast<Sprite*>(child));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue