我上的Xcode 6.0.1,我需要更新我的项目一个警告,所以我也...arc4random()停止更新项目工作后,线程1:EXC_ARITHMETIC
...但后来我与arc4random()%的问题,而不是
一切都被此更新之前工作正常,但现在我得到以下信息: “主题1:EXC_ARITHMETIC(代码= EXC_1386_DIV,子码=为0x0)和游戏崩溃
我用arc4random_uniform尝试过,但游戏似乎“停顿”,没有任何反应。我的意思是我可以看到它进入了我f(bType == pt || bType == pl)语句,但似乎“暂停”并无休止地循环。
有什么建议吗?
-(void)placeInGrid:(CGPoint)place pt:(int)pt pl:(int)pl amount:(int)amountOfbricks{
CCLOG(@"BRICKS:placeInGrid");
//CCLOG(@"pt %d", pt);
//CCLOG(@"pl %d", pl);
int bType = arc4random() % amountOfbricks;
//int bType = arc4random_uniform(amountOfbricks);
if(bType == pt || bType == pl){
CCLOG(@"bType == pt || bType == pl");
[self placeInGrid:place pt:pt pl:pl amount:amountOfbricks];
return;
}
else{
CCLOG(@"else");
CCSpriteBatchNode * b = (CCSpriteBatchNode *)[theGame getChildByTag:kSSheet];
mySprite = [CCSprite spriteWithBatchNode:b rect:[self setBrickType:bType]];
[b addChild:mySprite z:1];
self.bricksType =bType;
[self.mySprite setPosition:place];
}
}
UPDATE:
中的if-else下面的语句查找在游戏开始时保存的数据,看是否it's保存的游戏或新游戏。
问题看起来,在项目更新之后,游戏认为已经存储了数据,并且它会转到第一个if语句(if(gameData)),导致amountofbricks等于0,而不是进入else语句,其中amountofbricks等于4.
我不知道如何解决此问题。
if ([[GameManager sharedGameManager] isContinuePressed] == NO && [[GameManager sharedGameManager] isNewPressed] == YES) {
if(gameData){
CCLOG(@"gameData && isContinuePressed == NO && isNewPressed == YES");
//Set the local instance of myobject to the object held in the gameState filler with the key "myObject"
level = 1;
[[GameManager sharedGameManager] setHScore:[decoder decodeIntegerForKey:@"HighScore"]];
highscore = [[GameManager sharedGameManager] ReturnHScore];
countTime = 300;
AmountOfBricks = [[GameManager sharedGameManager] ReturnAmountOfBricks];
BeginningOfGame = YES;
CCLOG(@"AmountOfBricks %d", AmountOfBricks);
}
else{
CCLOG(@"!gameData && isContinuePressed == NO && isNewPressed == YES");
if([[GameManager sharedGameManager]isThereASavedGame] ==YES){
CCLOG(@"isThereASavedGame == YES");
score = 0;
highscore = [[GameManager sharedGameManager] ReturnHScore];
level = 1;
countTime = 300;
AmountOfBricks = 4;
BeginningOfGame = YES;
CCLOG(@"AmountOfBricks %d", AmountOfBricks);
}
else{
CCLOG(@"isThereASavedGame == NO");
score = 0;
highscore = 0;
level = 1;
countTime = 300;
AmountOfBricks = 4;
BeginningOfGame = YES;
CCLOG(@"AmountOfBricks %d", AmountOfBricks);
}
}
}
更新:我发现这个问题。
问题出在我的游戏manager.m文件中。
NSMutableData * gameData; NSKeyedUnarchiver * decoder = nil;
NSString *documentPath = [documentsDirectory stringByAppendingPathComponent: @"gameState.dat"];
gameData = [NSData dataWithContentsOfFile:documentPath];//before the update, I as using this line. was working perfectly. after the update I got a warning on this line "incompatible pointer" and xcode recommended to update to the line below but the line below started to return a zero value. which caused the game to crash.
//gameData = [NSMutableData dataWithData:[NSData dataWithContentsOfFile:documentPath]];
把它不容为零。在第一值为4。就像我说的,它给了价值4,直到我昨天更新了项目。 – Chris79 2014-10-04 10:28:54
你是否在更新之后验证了这一点?调用代码可能会受到更新的影响,现在对于amountOfBricks调用此方法的值为0。或者错误不在该代码中,请尝试添加异常断点以准确查看错误所在的行。 EXC_ARITHMETIC和EXC_1386_DIV明确指出了一个除零误差的情况。 – LearnCocos2D 2014-10-04 11:29:37
@ Chris79无论如何,你应该防止amountOfBricks为0.还要检查你是否正在构建新的体系结构,潜在的潜在int,long,long long,unsigned等等...... – YvesLeBorg 2014-10-04 11:35:31