0

更改场景时,我很难解决崩溃问题。这是被替换场景的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

谢谢。

4

1 回答 1

0

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

我认为问题在于 cocos2d 正在释放 CCDirector:setNextScene 的“运行场景”,在我允许它被释放之后。通过仔细检查我的发布和保留,我能够让它保留更长时间,以便让 cocos2d 有时间做它的内务。

我过于热心地试图不在任何地方保留我的对象,因此我使用了 CCScheduler UnscheduleAllSelectors,这对于像我这样的普通人来说是一个禁忌。对我来说,带回家的是:当你试图纠正它时,小心不要搞砸你的代码;并且要有耐心:逻辑是合乎逻辑的。此外,我学会了访问 cocos2d 源代码来帮助我,并且获得了更好的工具使用技能,尤其是堆检查。

于 2012-09-09T18:03:56.573 回答