开发者

Program crash, need help to find the problem at least where to look

I am getting the following messages before crash:

2011-01-02 00:55:15.935 XXXX[7981:207] answerButton1    
2011-01-02 00:55:15.938 XXXX[7981:207] >>>>>>>>>>>>>>>>>>>>nrQPlayer: 2
2011-01-02 00:55:15.939 XXXX[7981:207] =========whatPlayerCount===========
2011-01-02 00:55:15.939 XXXX[7981:207] ==whatPlayerCount== 1
2011-01-02 00:55:15.940 XXXX[7981:207] =========Spelare 1===========
2011-01-02 00:55:15.940 XXXX[7981:207] oooooooEND OF PLAYER!oooooooooo
2011-01-02 00:55:15.941 XXXX[7981:207] ooooooooooBEFORE IFooooooooooo
2011-01-02 00:55:15.942 XXXX[7981:207] INIT 0x5b9be30
2011-01-02 00:55:16.563 XXXX to be able to fix it[7981:207] *** -[ErrorMessage respondsToSelector:]: message sent to deallocated instance 0xca25ff0

I have been trying to track down exactly where the problem are, tried to test 'retain' in some places but somewhat running out of options now. When i try to run debugger with breakpoint but it get stuck and i cannot step forward.

I would appreciate any help possible. I am pretty new at this also, which doesn't make the situation better :-)

Here is the the part of the code that crash:

case 2: // Two players

        //nrQPlayer antal spelare
        NSLog(@"=========whatPlayerCount===========");
        NSLog(@"==whatPlayerCount== %i", whatPlayerCount);
        switch (whatPlayerCount) {
            case 1:
                NSLog(@"=========Spelare 1===========");
                playerDiff = 1;
                whatPlayerCount = 2;
                thePlayer = 0;
                NSLog(@"oooooooEND OF PLAYER!oooooooooo");
                break;
            case 2:
                NSLog(@"=========Spelare 2===========");
                playerDiff = 3;
          开发者_StackOverflow      whatPlayerCount = 1;
                thePlayer = 2;
                break;
            default:
                NSLog(@"=========break===========");
                break;
        }
        NSLog(@"ooooooooooBEFORE IFooooooooooo");
        NSLog(@"INIT %p", self);
        // >>>>>>>>HERE IS WHERE THE CRASH HAPPENS<<<<<<<<<<
        if (askedQuestions < nrOfQuestionsPerPlayer) {
            NSLog(@"1");
            if ([[finalPlayersInGame objectAtIndex:playerDiff] intValue] == 1) { // HARD
                NSLog(@"HARD 1");
                questionNr = [[hardQArray objectAtIndex:askedQuestions] intValue];
                qArray = [readQuestionFunction readQuestion: questionNr];
                question_TextView.text = [qArray objectAtIndex:0];
                NSLog(@"HARD - qNr: %i", questionNr);
            } 
            else if ([[finalPlayersInGame objectAtIndex:playerDiff] intValue] == 2) { // MEDIUM
                NSLog(@"2");
                questionNr = [[mediumQArray objectAtIndex:askedQuestions] intValue];
                qArray = [readQuestionFunction readQuestion: questionNr];
                question_TextView.text = [qArray objectAtIndex:0];
                NSLog(@"MEDIUM - qNr: %i", questionNr);
            }
            else if ([[finalPlayersInGame objectAtIndex:playerDiff] intValue] == 3) { // EASY
                NSLog(@"3");
                questionNr = [[easyQArray objectAtIndex:askedQuestions] intValue];
                qArray = [readQuestionFunction readQuestion: questionNr];
                NSLog(@"qArray: %@", qArray);
                NSLog(@"questionNr: %i", questionNr);
                question_TextView.text = [qArray objectAtIndex:0];
                NSLog(@"EASY - qNr: %i", questionNr);
            }
            NSLog(@"ooooooooooAFTER IFooooooooooo");

            NSLog(@"4");
            playerName_Label.text = [NSString stringWithFormat:@"Spelare: %@", [finalPlayersInGame objectAtIndex:thePlayer]];
            playerResult_Label.text = [NSString stringWithFormat:@"Fråga %i av %i", askedQuestions, nrOfQuestionsPerPlayer];

            //========CALL AccesQuestionDB MODULE TO SHUFFLE PLAYERS=========//
            AccessQuestionsDB *shufflePlayersFunction = [AccessQuestionsDB new];

            buttonOrder = [[NSMutableArray alloc] initWithObjects:@"1", @"2", @"3", nil];

            buttonOrder = [shufflePlayersFunction shufflePlayers: buttonOrder]; // Use shufflePlayers to shuffle button also
            NSLog(@"buttonOrder: %@", buttonOrder);
            [shufflePlayersFunction release];
            NSLog(@"5");
            //========CALL buttonsOrder=========//
            ButtonOrderAccess *buttonOrderFunction = [ButtonOrderAccess new];
            [buttonOrderFunction saveButtonOrder: buttonOrder];
            [buttonOrderFunction release];

            NSLog(@"qArray: %@", qArray);
            NSLog(@"buttonOrder: %@", buttonOrder);
            [self.answerButton1 setTitle:[qArray objectAtIndex:[[buttonOrder objectAtIndex:0]intValue]] forState:UIControlStateNormal];
            [self.answerButton2 setTitle:[qArray objectAtIndex:[[buttonOrder objectAtIndex:1]intValue]] forState:UIControlStateNormal];
            [self.answerButton3 setTitle:[qArray objectAtIndex:[[buttonOrder objectAtIndex:2]intValue]] forState:UIControlStateNormal];


            if (firstQuestion == YES) {
                firstQuestion = NO;
                //secondQuestion = YES;
            }
            else {
                askedQuestions++;
                firstQuestion = YES;
            }



        }
        else {
            // Call Error Message
            ErrorMessage *callErrorMessageFunction = [ErrorMessage new];
            [callErrorMessageFunction questionError: @"Q2"];
            [callErrorMessageFunction release];
        }


Use NSZombie, an object that catch messages sent to deallocated objects and prints the info in the console.

Refer to this question for detailed instructions: How to run iPhone program with Zombies instrument?


We cannot know what's happening behind the screen e.g. here:

ErrorMessage *callErrorMessageFunction = [ErrorMessage new];
[callErrorMessageFunction questionError: @"Q2"];
[callErrorMessageFunction release];

but it might very well be that something in this ErrorMessage object should live on a little longer.

To fix that, don't release, but autorelease. Upon return to the runloop the object will live on, which may be long enough for your (unknown) purposes.

The typical sequence would then be:

ErrorMessage *callErrorMessageFunction = [[[ErrorMessage alloc] init] autorelease];
[callErrorMessageFunction questionError: @"Q2"];

(I prefer alloc + init over new, but they are equivalent)


You're either releasing something you shouldn't release, or not retaining an autoreleased object that you need to keep around. Go read the memory management docs. We're not seeing enough of your code here to know which it is.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜