So here is the background code needed to understand my problem. In my view controller class, I have a method which creates an array called levelStart, that array is then sent to my game class which intialized itself with that array, then I have a set of functions that use this array to "play the game". Here is the view controller code:
NSMutableArray* levelStart = [[NSMutableArray alloc] init];
NSMutableArray* levelFinish = [[NSMutableArray alloc] init];
NSString* startString = [[NSString alloc] initWithString:@"9999999999988888888998888888899888888889988888888998888888899888888889911888888991188888899999999999"];
NSString* finishString = [[NSString alloc] initWithString:@"9999999999988888811998888881199888888889988888888998888888899888888889988888888998888888899999999999"];
int currentsquare;
for (int i = 0; i < 100; i++) {
currentsquare = [startString characterAtIndex:i] - '0';
if (currentsquare == 1) {
NSNumber* numb1 = [[NSNumber alloc] initWithInt:1];
[levelStart addObject:numb1];
}
if (currentsquare == 2) {
NSNumber* numb2 = [[NSNumber alloc] initWithInt:2];
[levelStart addObject:numb2];
}
if (currentsquare == 3) {
NSNumber* numb3 = [[NSNumber alloc] initWithInt:3];
[levelStart addObject:numb3];
}
if (currentsquare == 4) {
NSNumber* numb4 = [[NSNumber alloc] initWithInt:4];
[levelStart addObject:numb4];
}
if (currentsquare == 8) {
NSNumber* numb8 = [[NSNumber alloc] initWithInt:8];
[levelStart addObject:numb8];
}
if (currentsquare == 9) {
NSNumber* numb9 = [[NSNumber alloc] initWithInt:9];
[levelStart addObject:numb9];
}
}
for (int i = 0; i < 100; i++) {
currentsquare = [finishString characterAtIndex:i] - '0';
if (currentsquare == 1) {
NSNumber* fnumb1 = [[NSNumber alloc] initWithInt:1];
[levelFinish addObject:fnumb1];
}
if (currentsquare == 2) {
NSNumber* fnumb2 = [[NSNumber alloc] initWithInt:2];
[levelFinish addObject:fnumb2];
}
if (currentsquare == 3) {
NSNumber* fnumb3 = [[NSNumber alloc] initWithInt:3];
[levelFinish addObject:fnumb3];
}
if (currentsquare == 4) {
NSNumber* fnumb4 = [[NSNumber alloc] initWithInt:4];
[levelFinish addObject:fnumb4];
}
if (currentsquare == 8) {
NSNumber* fnumb8 = [[NSNumber alloc] initWithInt:8];
[levelFinish addObject:fnumb8];
}
if (currentsquare == 9) {
NSNumber* fnumb9 = [[NSNumber alloc] initWithInt:9];
[levelFinish addObject:fnumb9];
}
}
[startString release];
[finishString release];
//NOTE: I took out the intialization of control and level, both which work fine.
myGame = [[Game alloc] initLevel:level With:levelStart AndFinish:levelFinish WithRows:10 WithColumns:10 WithControl:control];
In my Game class this is the initalization method:
-(id)initLevel:(int)aLevel With:(NSMutableArray*)starter AndFinish:(NSMutableArray*)finisher WithRows:(int)rows WithColumns:(int)cols WithControl:(Coord)aControlSquare{
self = [super init];
if (self != nil){
level = aLevel;
squares = [[NSMutableArray alloc] init];
squares = starter;
finish = [[NSMutableArray alloc] init];
finish = finisher;
}
return self;
}
Now the method where it keeps freezing on is in Game, which is triggered by UIgesture recognizer, here is the line it freezes on:
if ([[self squareForCoord:test] intValue] == 8) {
...
}
where squareForCord takes the test coord and returns the NSNumber at that coord. So I have made sure all my tests are inside bounds, and the point it freezes on is in bounds of my array. I believe I am initializing everything correctly but obviously not, this is definately not a problem with releasing something released so I figure it must be an initalization issue, please help.