Cocos2d iphone 应用程序在目标c中的NSException处崩溃

Cocos2d iphone 应用程序在目标c中的NSException处崩溃,cocos2d-iphone,Cocos2d Iphone,这是我的代码。在这个方法中,我的应用程序在CheckIntersectOrNot方法处崩溃。在这个方法中,它在[self-DifferentColorBalls:loBall];行处崩溃;。在这方面,我也使用了异常,但它不起作用 -(void)CheckIntersectOrNot:(BallImage *)loBall{ BallImage *loTar = (BallImage *)[self getChildByTag:200]; if (CGRec

这是我的代码。在这个方法中,我的应用程序在CheckIntersectOrNot方法处崩溃。在这个方法中,它在[self-DifferentColorBalls:loBall];行处崩溃;。在这方面,我也使用了异常,但它不起作用

    -(void)CheckIntersectOrNot:(BallImage *)loBall{
        BallImage *loTar = (BallImage *)[self getChildByTag:200];
        if (CGRectIntersectsRect([loTar boundingBox], [loBall boundingBox])) {
            [loTar stopAllActions];
            checkCollsionEnable = YES;
            if (loTar.BallColor == loBall.BallColor) {
                //same color
                [self SameColorBall:loBall TargetBall:loTar];
            }
            else{
                //different color balls
                @try {
                    if (loBall != nil ) {
                        [loBall retain];
                        if (GameOverCompleted == 2) {
                            return;
                        }
                        [self DifferentColorBalls:loBall];
                    }
                }
                @catch (NSException *exception) {
                    NSLog(@"exception:%@",exception);
                }
            }
            checkCollsionEnable = NO;
        }
    }

    -(void)DifferentColorBalls:(BallImage *)loBall{
        if (GameOverCompleted == 2 ) {
            return;
        }
         [[SimpleAudioEngine sharedEngine] playEffect:@"BallSound2.wav"];
        @try {

            CGPoint tarPoint;
            BallImage *loTar = (BallImage *)[self getChildByTag:200];
            int index = [self.mBallImageArray indexOfObject:loBall];
            tarPoint = loBall.position;
            int ballangle = loBall.ballAngle;
            int ballDirection = loBall.BallDirection;
            for (int i = index; i>= 0; i--) {
                BallImage *loba = [self.mBallImageArray objectAtIndex:i];
                [self Movenext:loba];
            }
            [loTar setTag:-1];
            loTar.BallAnimationEnable = 1;
            loTar.position = tarPoint;
            loTar.ballAngle = ballangle;
            loTar.BallDirection = ballDirection;
            @try {
                if (loTar != nil) {
                    [self.mBallImageArray insertObject:loTar atIndex:++index];
                }
            }
            @catch (NSException *exception) {
                NSLog(@"differnet loTar ball :%@",exception);
            }

            [self CreteTargetBallImage];
        }
        @catch (NSException *exception) {
            NSLog(@"exception DifferentColorBalls :%@",exception);
        }
        @finally {

        }

    }
    -(void)Movenext:(BallImage *)loBall{
        int loop = loBall.contentSize.width/AnimationMoveLength;
        for (int i = 0; i<loop; i++) {
            @try {
                [self BallNextposition:loBall];
            }
            @catch (NSException *exception) {
                NSLog(@"Movenext exception :%@",exception);
            }
        }

    }
    -(void)BallNextposition:(BallImage *)loBall{

        [self DisableForBallAnimation:loBall];
        if (!loBall.BallAnimationEnable) {
            return;
        }
        if (loBall.BallForwardEnable == 0) {
            [self MoveBackPosition:loBall];
            return;
        } 
        CGPoint point1, point2, point3;
        CGPoint ballPosition = loBall.position;
        CGRect BoxRect = CGRectMake(40, 40, 22, 244);
        CGRect BoxRect2 = CGRectMake(40, 0, 100, 40);
        CGRect BoxRect3 = CGRectMake(94, 40, 22, 207);
        CGRect BoxRect4 = CGRectMake(94, 245, 100, 44);
        CGRect BoxRect12 = CGRectMake(363, 10, 80, 34);
        CGRect BoxRect13 = CGRectMake(418, 40, 24, 233);
        CGRect BoxRect14 = CGRectMake(405, 272, 50, 50);
        if (CGRectContainsPoint(BoxRect, ballPosition) && loBall.BallDirection == 0) {        
            point1 = CGPointMake(50, 283);
            point2 = CGPointMake(50, 40);
           loBall.position =  [self DrawStrightLine:point1 SecondPoint:point2 BallMovementlength:AnimationMoveLength t:loBall.ballAngle];
            loBall.ballAngle++;
            if (CGRectContainsPoint(BoxRect2, loBall.position)) {
                loBall.ballAngle = 1;
                loBall.BallDirection = 1;
            }
        }
        else if (CGRectContainsPoint(BoxRect2, ballPosition) && loBall.BallDirection == 1) {
            point1 = CGPointMake(50, 40);
            point2 = CGPointMake(77, 10);
            point3 = CGPointMake(104, 40);
            loBall.position = [self DrawCurve:point1 secondPoint:point2 thirdPoint:point3 BallMovementlength:AnimationMoveLength t:loBall.ballAngle];
            loBall.ballAngle++;
            if (CGRectContainsPoint(BoxRect3, loBall.position)) {
                loBall.ballAngle = 1;
                loBall.BallDirection = 2;
            }
        }
        else if (CGRectContainsPoint(BoxRect13, ballPosition) && loBall.BallDirection == 13){
           // AnimationMoveLength = 4;
          //  loBall.BallForwardEnable = 0;
            GameOverCompleted = 2;
            [self GameOver];
            [self RemoveBallsFromBG:loBall];

        }
        else{
            NSLog(@"loBall.position:%@",NSStringFromCGPoint(loBall.position));
        }
    }

    -(void)RemoveBallsFromBG:(BallImage *)loBall{
        [loBall runAction:[CCScaleTo actionWithDuration:0.1 scale:.1]];
        [self.mBallImageArray removeObject:loBall];
        [self removeChild:loBall cleanup:YES];
        loBall = nil;
        BallImage *loTarSpr = (BallImage *)[self getChildByTag:200];
        [self removeChild:loTarSpr cleanup:YES];
        loTarSpr = nil;
        if ([self.mBallImageArray count] == 0) {
            [self unscheduleAllSelectors];
            [self LossGame];
        }
    }
    -(void)GameOver{

        static int i = 0;
        if (i == 0) {
            i++;
            for (int loop = 0; loop < [self.mBallImageArray count]; loop++) {
                BallImage *loBall = [self.mBallImageArray objectAtIndex:loop];
                loBall.BallAnimationEnable = 1;
            }
            [self unscheduleAllSelectors];
            [self schedule:@selector(MoveBall:)];
        }
        if ([self.mBallImageArray count] == 0) {
            [self LossGame];
            [self unscheduleAllSelectors];
            i = 0;
        }
    }

    -(void)WinGame{
        GameOverCompleted = 2;
        NSLog(@"WinGame");
        [[SimpleAudioEngine sharedEngine] stopBackgroundMusic];
        [CommonUserDetails sharedUserDetails].GameWinOrNot = 1;
        [CommonUserDetails sharedUserDetails].GameScore = TotalScore;
        [[CommonUserDetails sharedUserDetails].HighScoreArray addObject:[NSString stringWithFormat:@"%d",TotalScore]];
        if ([[CommonUserDetails sharedUserDetails].HighScoreArray count] > 50) {
            [[CommonUserDetails sharedUserDetails].HighScoreArray removeObjectAtIndex:0];
        }
        [[CommonUserDetails sharedUserDetails] saveToUserDefaults];
        [self unscheduleAllSelectors];
        [[CCDirector sharedDirector] replaceScene:[GameOverScene node]];
    }
    -(void)LossGame{
        GameOverCompleted = 2;
        [[SimpleAudioEngine sharedEngine] stopBackgroundMusic];
        [CommonUserDetails sharedUserDetails].GameWinOrNot = 0;
        [CommonUserDetails sharedUserDetails].GameScore = TotalScore;
        [[CommonUserDetails sharedUserDetails].HighScoreArray addObject:[NSString stringWithFormat:@"%d",TotalScore]];
        if ([[CommonUserDetails sharedUserDetails].HighScoreArray count] > 50) {
            [[CommonUserDetails sharedUserDetails].HighScoreArray removeObjectAtIndex:0];
        }
        [[CommonUserDetails sharedUserDetails] saveToUserDefaults];
        [self unscheduleAllSelectors];
        [[CCDirector sharedDirector] replaceScene:[GameOverScene node]];
        NSLog(@"Loss Game");
    }
请任何人帮我解决这个问题。为什么它会崩溃,并就这个问题给出任何建议
非常感谢

太多的代码,没有异常。您在控制台中看到什么异常情况?您的代码不容易阅读,我在控制台中看不到任何东西。当应用程序崩溃时,我看到程序收到信号:EXC\u BAD\u accessemm。。。你为什么认为这意味着例外?EXC_BAD_ACCESS表示您尝试使用不存在的对象非常感谢您的建议在Xcode中添加一个异常断点,让它显示导致异常的确切行。