CCSpriteBatchNode use after release.

Hello.

I have found bug in CCSpriteBatchNode. When CCSpriteBatchNode is destroyed it doesn’t set NULL for children (like in CCNode). Here is case when i have this kind of situation. My childs are retained so when CCSpriteBatchNode is destroyed childs still have pointer to destroyed CCSpriteBatchNode.

Resulution will be to do the same like in CCNode simply iterate through childs an set batch node to NULL

My destructor look like:

CCSpriteBatchNode::~CCSpriteBatchNode()
{
    if(m_pChildren && m_pChildren->count() > 0)
    {
        CCObject* child;
        CCARRAY_FOREACH(m_pChildren, child)
        {
            CCSprite* pChild = (CCSprite*) child;
            if (pChild)
            {
                pChild->setBatchNode(NULL);
            }
        }
    }
    CC_SAFE_RELEASE(m_pobTextureAtlas);
    CC_SAFE_RELEASE(m_pobDescendants);
}

Should i make a PR for this? I have this on cocos2dx master branch.
https://github.com/cocos2d/cocos2d-x/blob/master/cocos2dx/sprite_nodes/CCSpriteBatchNode.cpp

I’m interested as to why you’re running into this problem. I’m using a lot of CCSpriteBatchNodes in fairly sophisticated configurations and the current code (which is faster) works well here.

Releasing m_pobDescendants seems to be enough for most people’s projects.

Ok you can use a lot of CCSpriteBatchNodes but still if your CCSprites are retained and for example you call removeFromParent() you will have this kind of error because m_pobBatchNode != NULL and it points to something that is released.

The same work is done in CCNode but not in CCSpriteBatchNodes.

Pull request: https://github.com/cocos2d/cocos2d-x/pull/5502