Skip to content

BUG - Was mutated while being enumerated exception while adding a child. #908

Open
@vladubogdan

Description

@vladubogdan

If you execute the following code

-(void)mouseDown:(NSEvent *)theEvent{

    NSPoint location = [theEvent locationInNode:self];

    CCSprite* parentSpr = [CCSprite spriteWithImageNamed:@"test.png"];
    if(parentSpr){
        NSLog(@"ADDING PARENT SPR %p", parentSpr);
        [parentSpr setPosition:location];

        CCSprite* newChildSpr = [CCSprite spriteWithImageNamed:@"test.png"];
        [newChildSpr setPosition:CGPointMake(30, 0)];
        NSLog(@"ADD CHILD %p", newChildSpr);
        [parentSpr addChild:newChildSpr];

        [self addChild:parentSpr];
    }

    [super mouseDown:theEvent];
}

Eventually you will get this exception

An uncaught exception was raised
2014-07-30 15:13:11.503 Cocos2d31ExceptionTest[19573:8403] *** Collection <__NSArrayM: 0x610000046cc0> was mutated while being enumerated.
2014-07-30 15:13:11.503 Cocos2d31ExceptionTest[19573:8403] (
    0   CoreFoundation                      0x00007fff8a12925c __exceptionPreprocess + 172
    1   libobjc.A.dylib                     0x00007fff8d41ee75 objc_exception_throw + 43
    2   CoreFoundation                      0x00007fff8a128b64 __NSFastEnumerationMutationHandler + 164
    3   Cocos2d31ExceptionTest              0x000000010008c377 -[CCNode visit:parentTransform:] + 407
    4   Cocos2d31ExceptionTest              0x000000010008c8cc -[CCNode visit] + 508
    5   Cocos2d31ExceptionTest              0x0000000100054ef3 -[CCDirectorDisplayLink drawScene] + 755
    6   Cocos2d31ExceptionTest              0x00000001000546bc -[CCDirectorDisplayLink getFrameForTime:] + 188
    7   Cocos2d31ExceptionTest              0x00000001000549a7 MyDisplayLinkCallback + 55
    8   CoreVideo                           0x00007fff88ee75cc _ZN13CVDisplayLink9performIOEP11CVTimeStamp + 206
    9   CoreVideo                           0x00007fff88ee6a08 _ZN13CVDisplayLink11runIOThreadEv + 608
    10  CoreVideo                           0x00007fff88ee678f _ZL13startIOThreadPv + 147
    11  libsystem_pthread.dylib             0x00007fff88e67899 _pthread_body + 138
    12  libsystem_pthread.dylib             0x00007fff88e6772a _pthread_struct_init + 0
    13  libsystem_pthread.dylib             0x00007fff88e6bfc9 thread_start + 13
)

I've uploaded a test project on dropbox here

https://dl.dropboxusercontent.com/u/27229440/Temporary/Cocos2d31ExceptionTest.zip

To test it successfully just run the project and then click really fast in the scene.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions