cocos2d / cocos2d-objc

Cocos2d for iOS and OS X, built using Objective-C
http://www.cocos2d-objc.org
Other
4.07k stars 1.16k forks source link

Loading a scene twice makes it crash during transition #779

Closed fgeorg closed 10 years ago

fgeorg commented 10 years ago

As of the 3.1 beta the following code snippet crashes. Removing the (obviously useless) first line fixes it. Still, I think cocos2d/Spritebuilder shouldn't crash in this case.

[CCBReader loadAsScene:@"SecondScene" owner:self];
[[CCDirector sharedDirector] replaceScene:[CCBReader loadAsScene:@"SecondScene" owner:self]];

Changing CCAction.h:47 id unsafe_unretained _originalTarget; id unsafe_unretained _target;

to be __weak also fixes the crash, which leads me to believe that this points to a larger memory management issue.

link to sample project repro case: https://www.dropbox.com/sh/mpv5uejo6pr5r4o/AADG8XXbxigWcDcTYPMY9RRBa

stack trace of the crash:

#0  0x01dfad85 in objc_retain ()
#1  0x01dfbfd0 in objc_storeStrong ()
#2  0x0001d797 in -[CCActionInterval startWithTarget:] at /Users/fgeorg/wooga/TransitionCrash.spritebuilder/Source/libs/cocos2d-iphone/cocos2d/ CCActionInterval.m:101
#3  0x0001e72c in -[CCActionSequence update:] at /Users/fgeorg/wooga/TransitionCrash.spritebuilder/Source/libs/cocos2d-iphone/cocos2d/  CCActionInterval.m:261
#4  0x0001d748 in -[CCActionInterval step:] at /Users/fgeorg/wooga/TransitionCrash.spritebuilder/Source/libs/cocos2d-iphone/cocos2d/    CCActionInterval.m:93
#5  0x0009dee7 in -[CCBAnimationManager updateInternal:] at /Users/fgeorg/wooga/TransitionCrash.spritebuilder/Source/libs/cocos2d-iphone/cocos2d    -ui/CCBReader/CCBAnimationManager.m:861
#6  0x0009dc05 in -[CCBAnimationManager update:] at /Users/fgeorg/wooga/TransitionCrash.spritebuilder/Source/libs/cocos2d-iphone/cocos2d-ui/    CCBReader/CCBAnimationManager.m:840
#7  0x0005685f in InvokeMethods at /Users/fgeorg/wooga/TransitionCrash.spritebuilder/Source/libs/cocos2d-iphone/cocos2d/CCScheduler.m:89
#8  0x000581ef in -[CCScheduler update:] at /Users/fgeorg/wooga/TransitionCrash.spritebuilder/Source/libs/cocos2d-iphone/cocos2d/CCScheduler.   m:519
#9  0x000dd660 in -[CCDirectorIOS drawScene] at /Users/fgeorg/wooga/TransitionCrash.spritebuilder/Source/libs/cocos2d-iphone/cocos2d/Platforms/ iOS/CCDirectorIOS.m:114
#10 0x000df87c in -[CCDirectorDisplayLink mainLoop:] at /Users/fgeorg/wooga/TransitionCrash.spritebuilder/Source/libs/cocos2d-iphone/cocos2d/   Platforms/iOS/CCDirectorIOS.m:361
#11 0x005642d2 in CA::Display::DisplayLink::dispatch(unsigned long long, unsigned long long) ()
#12 0x0056475f in CA::Display::TimerDisplayLink::callback(__CFRunLoopTimer*, void*) ()
#13 0x01f82376 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ ()
#14 0x01f81e06 in __CFRunLoopDoTimer ()
#15 0x01f69a82 in __CFRunLoopRun ()
#16 0x01f68f44 in CFRunLoopRunSpecific ()
#17 0x01f68e1b in CFRunLoopRunInMode ()
#18 0x03b407e3 in GSEventRunModal ()
#19 0x03b40668 in GSEventRun ()
#20 0x00c35ffc in UIApplicationMain ()
#21 0x000028dc in main at /Users/fgeorg/wooga/TransitionCrash.spritebuilder/Source/main.m:14
cocojoe commented 10 years ago

Thanks, I agree it shouldn't crash, I was actually going to raise a related issue about this same topic today. I'll reference this in it.

fgeorg commented 10 years ago

This seems to have been fixed after upgrading to release-3.1.0-rc.1 [523ee6bcab]