Projects > cpp > Issues > Bug #4054

We are migrating issue tracker of Cocos2d-x Project to Github, please create new issue there. Thanks.

Create Issue on Github

Removing child from TMXLayer may cause crash.

Bug #4054 [Closed]
dumganhar 2014-02-17 10:18 . Updated over 9 years ago

The codes in addSpriteWithoutQuad from cocos2d-iphone is:

-(id) addSpriteWithoutQuad:(CCSprite*)child z:(NSUInteger)z name:(NSString*)name
{
... 
    // XXX: optimize with a binary search
    int i=0;
    for( CCSprite *c in _descendants ) {
        if( c.atlasIndex >= z )    // Here we check if index is larger than z, break, so the element's atlastIndex in _descendants is from high value to low value.
            break;
        i++;
    }
    [_descendants insertObject:child atIndex:i];
...
}
@end

BUT IN COCOS2D-X, THE LOGIC WAS TOTALLY DIFFERENT.

CCSpriteBatchNode * CCSpriteBatchNode::addSpriteWithoutQuad(CCSprite*child, unsigned int z, int aTag)
{
...
    // XXX: optimize with a binary search
    int i=0;

    CCObject* pObject = NULL;
    CCARRAY_FOREACH(m_pobDescendants, pObject)
    {
    CCARRAY_FOREACH(m_pobDescendants, pObject)
    {
        CCSprite* pChild = (CCSprite*) pObject;
        if (pChild && (pChild->getAtlasIndex() >= z))   // Wrong logic here.........shit
        {
            ++i;
        }
    }
...
}

OUCH.

dumganhar 2014-02-17 13:25
dumganhar 2014-02-19 03:35
  • Status changed from New to Closed
  • % Done changed from 0 to 100

Applied in changeset commit:34e6364f42f1f10a4a9d0a25012e6956508e3dc7.

Atom PDF

Status:Closed
Start date:2014-02-17
Priority:Normal
Due date:
Assignee:dumganhar
% Done:

100%

Category:all
Target version:3.0-rc0