gpt4 book ai didi

objective-c - 程序崩溃,需要帮助才能至少在哪里找到问题

转载 作者:行者123 更新时间:2023-12-03 16:57:07 25 4
gpt4 key购买 nike

崩溃前我收到以下消息:

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

我一直在尝试准确地找出问题所在,尝试在某些地方测试“保留”,但现在有些选项用完了。当我尝试使用断点运行调试器但卡住并且无法前进时。

我将不胜感激。我对此也很陌生,这并不能使情况变得更好:-)

这是崩溃的代码部分:

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

最佳答案

我们不知道屏幕后面发生了什么,例如这里:

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

但很可能是该 ErrorMessage对象中的某些内容应该存在更长的时间。

要解决此问题,请不要使用 release,而不要使用 autorelease。返回到运行循环后,对象将继续存在,对于您(未知)的目的而言,该对象可能足够长。

然后,典型序列为:
ErrorMessage *callErrorMessageFunction = [[[ErrorMessage alloc] init] autorelease];
[callErrorMessageFunction questionError: @"Q2"];

(与 alloc相比,我更喜欢 init + new,但它们是等效的)

关于objective-c - 程序崩溃,需要帮助才能至少在哪里找到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4576450/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com