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]
}

リストされた重要なオブジェクトの解放が呼び出されることを確認しました。

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 に答える