Whenever I call the doSomething function my program crashes. The actual code as a bit of array bounds checking, so I know that's not an issue.
myClass.h
#import <Foundation/Foundation.h>
@interface myClass : NSObject {
BOOL **myMatrix;
}
@property(readwrite) BOOL **myMatrix;
-(myClass*)initWithWidth: (int)w andHeight: (int)h;
-(void)doSomething;
+(BOOL **) createMatrixWithHeight: (int)h andWidth: (int)w;
@end
myClass.m
#import "myClass.h"
#import <Foundation/Foundation.h>
@implementation myClass
@synthesize myMatrix;
-(myClass*)initWithWidth: (int)w andHeight: (int)h {
self = [super init];
myMatrix = [myClass createMatrixWithHeight: h andWidth: w];
return self;
}
-(void)doSomething{
myMatrix[2][2] = YES;
}
+(BOOL **) createMatrixWithHeight: (int)h andWidth: (int)w{
BOOL **newMatrix;
newMatrix = malloc(w * sizeof(BOOL *));
int i;
for(i = 0; i < w; i++){
newMatrix[i] = malloc(h * sizeof(BOOL));
}
return newMatrix;
}
@end