Cocos2d在[CCDirector setNextScene]崩溃

时间:2012-09-09 15:18:11

标签: ios xcode cocos2d-iphone

我在更改场景时难以解决崩溃问题。这是被替换的场景的dealloc方法。它被调用,我知道没有内存泄漏或堆膨胀。任何人都可以建议我可能犯的愚蠢/明显的错误。我为白痴道歉。

-(void) dealloc
{
NSLog(@"Dungeon.m dealloc called");

[self removeAllChildrenWithCleanup:true];
[self unscheduleAllSelectors];
[[CCScheduler sharedScheduler]unscheduleAllSelectors];

if (entityList) [entityList release];
if (lopsidedList) [lopsidedList release];
if (monsterNames) [monsterNames release];
if (menuSprites) [menuSprites release];
if (menuLabels) [menuLabels release];
if (monsterLevels) [monsterLevels release];
if (theMagicFactory) [theMagicFactory release];
if (theDM) [theDM release];
if (theDisplay) [theDisplay release];
if (aDungeonLevel) [aDungeonLevel release];
NSLog([NSString stringWithFormat:@"Player Retain Count: %i",[thePlayer retainCount]]);

[super dealloc]
}

我已经确认调用了重要列出的对象的deallocs:

2012-09-09 10:51:31.840 Pocket Dungeons[947:707] Dungeon.m dealloc called
2012-09-09 10:51:31.878 Pocket Dungeons[947:707] DungeonMaster.m dealloc called.
2012-09-09 10:51:31.910 Pocket Dungeons[947:707] DungeonDisplay.m dealloc called
2012-09-09 10:51:31.915 Pocket Dungeons[947:707] dungeonlevel.m dealloccalled

这是不断变化的场景代码:

            else if (whatIsHere==STAIRS_UP) {
                if (thePlayer.currentDungeonLevel==1) {
                    NSLog([NSString stringWithFormat:@"Self Retain Count: %i",[self retainCount]]);
                    thePlayer.theDungeon = nil;
                    theDM.theDungeon = nil;
                    theDisplay.theDungeon = nil;

                    for (int i=0; i<[aDungeonLevel.mArray count]; i++) {
                        Monster *aMonster = [aDungeonLevel.mArray objectAtIndex:i];
                        aMonster.theDungeon = nil;
                    }


                    NSLog([NSString stringWithFormat:@"Self Retain Count: %i",[self retainCount]]);
//                    CCScene *aScene = [Town nodeWithPlayer:thePlayer];
                    CCScene *aScene = [CharacterMaker2 nodeWithPlayer:thePlayer];
                    [[CCDirector sharedDirector] replaceScene:aScene];

这是发生崩溃的地方:

0   0x34311f78 in objc_msgSend ()

1   0x000fef28 in -[CCDirector setNextScene] at /Users/nehrujuman212/Documents/Pocket Dungeons/Pocket Dungeons/libs/cocos2d/CCDirector.m:429

2   0x0014ab44 in -[CCDirectorIOS drawScene] at /Users/nehrujuman212/Documents/Pocket Dungeons/Pocket Dungeons/libs/cocos2d/Platforms/iOS/CCDirectorIOS.m:160

3   0x0014c858 in -[CCDirectorDisplayLink mainLoop:] at /Users/nehrujuman212/Documents/Pocket Dungeons/Pocket Dungeons/libs/cocos2d/Platforms/iOS/CCDirectorIOS.m:721

4   0x33fd386e in CA::Display::DisplayLink::dispatch(unsigned long long, unsigned long long) ()

5   0x33fd37c4 in CA::Display::IOMFBDisplayLink::callback(__IOMobileFramebuffer*, unsigned long long, unsigned long long, unsigned long long, void*) ()

6   0x37387000 in IOMobileFramebufferVsyncNotifyFunc ()

7   0x31bf060c in IODispatchCalloutFromCFMessage ()

8   0x3228af12 in __CFMachPortPerform ()

9   0x32295522 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()

10  0x322954c4 in __CFRunLoopDoSource1 ()

11  0x32294312 in __CFRunLoopRun ()

12  0x322174a4 in CFRunLoopRunSpecific ()

13  0x3221736c in CFRunLoopRunInMode ()

14  0x3136e438 in GSEventRunModal ()

15  0x31d16cd4 in UIApplicationMain ()

16  0x0016ea1e in main at /Users/nehrujuman212/Documents/Pocket Dungeons/Pocket Dungeons/main.m:14

感谢。

1 个答案:

答案 0 :(得分:0)

希望我可以充分回答我自己的问题,尽管答案可以使用一些进一步的输入。

我认为问题在于cocos2d正在发布&#34;正在运行的场景&#34;来自CCDirector:setNextScene,在我允许它被解除分配之后。通过仔细检查我的发布和保留,我能够让它保留更长时间,以便让cocos2d有时间进行管理。

我过于热心地试图不在任何地方保留我的物品,因为我使用了CCScheduler UnscheduleAllSelectors,这对像我这样的普通人来说是禁忌。对我来说,最重要的是:当你试图纠正它时,小心不要搞砸你的代码;并保持耐心:逻辑是合乎逻辑的。另外,我学会了访问cocos2d源代码来帮助我,并且在使用这些乐器方面也获得了更好的技巧,尤其是对堆的检查。