Hey
i have a NSArray * variable (called _heightMap) in my custom patch class. In init: i create it...
The first time execute: is called
It traces the _heightMap value. But the second time the program freezes and debug comes up. If i 'continue' i get a bad access or something similar error.
I'm assuming that something happens to my _heightMap to cause any reads from it throw an error, perhaps its been freed. This must happen after the execute: but i have no idea by what, or when.
Has anyone had any other problems like this?
I notice in simpleLandGenerator: i return a pointer of the mutable array typecasted as an NSArray, the mutable array is a subclass of NSArray so there shouldn't be any dramas here should there?
Any help would be super
i have a NSArray * variable (called _heightMap) in my custom patch class. In init: i create it...
Code:
-(NSArray *)generateHeightMap:(double)maxHeight
minHeight:(double)minHeight
numPoints:(int)numPoints
{
// Create mutable array to hold the points
NSMutableArray *heightMap;
heightMap = [NSMutableArray arrayWithCapacity:numPoints];
// cycle through each point
NSInteger i;
for (i=0; i<numPoints; i++) {
NSNumber *nextHeight;
nextHeight = [NSNumber numberWithDouble:rand()%100/100.0*maxHeight + minHeight];
[heightMap insertObject:nextHeight atIndex:0];
}
return (NSArray *)heightMap;
}
- (id) init
{
NSLog(@"init:");
if(self = [super init]) {
// Set random seed
[[NSDate date] timeIntervalSince1970];
_heightMap = [self generateHeightMap:DEFAULTINPUTMAXHEIGHT
minHeight:DEFAULTINPUTMINHEIGHT
numPoints:DEFAULTINPUTNUMPOINTS];
}
return self;
}
The first time execute: is called
Code:
- (BOOL) execute:(id<QCPlugInContext>)context atTime:(NSTimeInterval)time withArguments:(NSDictionary*)arguments
{
NSLog([_heightMap description]);
return YES;
}
It traces the _heightMap value. But the second time the program freezes and debug comes up. If i 'continue' i get a bad access or something similar error.
I'm assuming that something happens to my _heightMap to cause any reads from it throw an error, perhaps its been freed. This must happen after the execute: but i have no idea by what, or when.
Has anyone had any other problems like this?
I notice in simpleLandGenerator: i return a pointer of the mutable array typecasted as an NSArray, the mutable array is a subclass of NSArray so there shouldn't be any dramas here should there?
Any help would be super