문제

im new to programming in Objective C and really even to programming kind of. I am making a little and simple pong game and while i was trying to make an AI for the computer player the program always "shuts down" showing me SIGABRT error in Thread 1.

I already asked this question here, but didn't really got the answer, just been asked for providing more code.

The error really came out of nowhere a was editing code and suddenly it showed up and even after deleting the code o have written since the last successful building it still shows me the error. Even if i start a backup which i know worked.

So here is all the code i have.

PongViewController.m - the code i was editing before the error showed up

#import "pongViewController.h"

#define kGameStateRunning 1 
#define kGameStatePaused 2

#define kMicSpeedX 3 
#define kMicSpeedY 4

#define ObtiznostPocitace 15

@implementation pongViewController

@synthesize mic,plosina_a,plosina_b,hrac_score,pocitac_score,gameState,micVelocity,TapToBegin;


- (void)viewDidLoad {
    [super viewDidLoad];
    self.gameState = kGameStatePaused;
    micVelocity = CGPointMake(kMicSpeedX, kMicSpeedY);
    [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(gameLoop) userInfo:nil repeats:YES];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    if(gameState == kGameStatePaused) {
        TapToBegin.hidden = YES;
        gameState = kGameStateRunning;
    } else if (gameState == kGameStateRunning) {
        [self touchesMoved:touches withEvent:event];
    }
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint location = [touch locationInView:touch.view];
    CGPoint xLocation = CGPointMake(location.x,plosina_a.center.y);
    plosina_a.center = xLocation;
}

- (void) gameLoop {
    if(gameState == kGameStateRunning) {

        mic.center = CGPointMake(mic.center.x + micVelocity.x, mic.center.y + micVelocity.y);

        if(mic.center.x > self.view.bounds.size.width || mic.center.x < 0) {
            micVelocity.x = -micVelocity.x;
        }

        if(mic.center.y > self.view.bounds.size.height || mic.center.y < 0) {
            micVelocity.y = -micVelocity.y;
        }
    } else {
        if (TapToBegin.hidden) {
            TapToBegin.hidden = NO;
        }
    }

    //Collision Detection

    if (CGRectIntersectsRect(mic.frame,plosina_a.frame)) {
        if (mic.center.y < plosina_a.center.y) {
            micVelocity.y = -micVelocity.y;
            //NSLog(@"%f %f", mic.center,plosina_b.center);
        }
    }

    if (CGRectIntersectsRect(mic.frame,plosina_b.frame)) {
        if (mic.center.y > plosina_b.center.y) {
            micVelocity.y = -micVelocity.y;
        }
    }

    if(mic.center.y <= self.view.center.y) {
        if(mic.center.x < plosina_b.center.x) {
            CGPoint compLocation = CGPointMake(plosina_b.center.x - ObtiznostPocitace, plosina_b.center.y);
            plosina_b.center = compLocation;
        }

        if(mic.center.x > plosina_b.center.x) {
            CGPoint compLocation = CGPointMake(plosina_b.center.x + ObtiznostPocitace, plosina_b.center.y);
            plosina_b.center = compLocation;
        }
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

//jakovždy nakonec uvolníme co sme si obsadili

- (void)dealloc {
    [super dealloc];
    [mic release];
    [plosina_a release];
    [plosina_b release];
    [hrac_score release];
    [pocitac_score release];
    [TapToBegin release];

}

@end

main.m - the code where the error is pointing at

#import <UIKit/UIKit.h>

int main(int argc, char *argv[]) {

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);

    [pool release];
    return retVal;
}

What the Debugger is spitting out:

argc    int 1
argv    char ** 0xbffff6f4
*argv   char *  0xbffff800
pool    NSAutoreleasePool * 0x4b29340
NSObject    NSObject    {...}
_token  void *  0x521a200
_reserved3  void *  0x0
_reserved2  void *  0x0
_reserved   void *  0x0
retVal  int -1073744132

And this (from the Debugger console) but i think this isn't the part of the problem, but what the hell do i know.

This GDB was configured as "x86_64-apple-darwin".Attaching to process 11032.
Couldn't register com.yourcompany.pong with the bootstrap server. Error: unknown error code.
This generally means that another instance of this process was already running or is hung in the debugger.sharedlibrary apply-load-rules all
Current language:  auto; currently objective-c
(gdb) 

Please help, i tried fixing all the warnings i had in the application, i successed, but still nothing.

도움이 되었습니까?

해결책

Make a new project, make it a view based application, and call the project iTennis. on the website that you mentioned, http://www.icodeblog.com/2009/01/15/iphone-game-programming-tutorial-part-1/ download all the image files that it wants you to download, and place them in the resources folder of the project.

after this, open up the file iTennisViewController.xib and link pictures to the IBOutlets that you declared in the header file. Also if you don't know how to do this, I think there is a link for a video on the website on how to do it. If you don't see a link, go to youtube and watch TheNewBoston's videos on xcode. He teaches you the basics about this stuff, and you should watch his videos anyway.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top