I’ve hit this assert/crash from a couple of different things in my own code. It bothers me that it’s assuming the child is a sprite at all. Just now I hit it trying to add a label as a child of another label (Just experimenting with a simple hack to get drop shadows with my bitmap font). CCLabelBMFont does not derive from CCSprite at all, but this function assumes any child of a CCSpriteBatchNode, which CCLabelBMFont does inherit from, must be a CCSprite. So trying to add a CCLabelBMFont as a child of another CCLabelBMFont will crash here.
I’m guessing (when I should really be going to look so as to be more helpful) that the Obj-C version does a type check on the object to make sure it’s actually a sprite, and if not, just passes it on to CCNode’s addChild. In this version, assuming the CCNode it is passed can be typecast to a CCSprite when it really shouldn’t be causes undefined behavior at best, which is usually an instant crash.
Is there any kind of type checking available to CCObject or CCNode that could be used here to assert if the CCNode is not a sprite, rather than treating it as one and crashing?
I’m new to cocos2d in general, not just the C++ version, so take this with a grain of salt, maybe I really am only supposed to be adding other CCSprites as children of these things.
I’m not on the latest version either, though this function looks the same up to the assert.