I am working with the 3D model in iOS using Open GL and Objective C. I have 3 different 3D model files which contains the vertex, normal and index information. And when I start reading this file from Document directory it reads indexes file but when It starts reading Normal or Vertex file it throws error terminated due to memory issue. And this issue is happing only on iPhone 6 and 6Plus. I have tested this on iPhone 5C, 5S, 6S and 7 and its works perfectly no memory issue.
So can you help me out how can i resolve issue for iPhone 6 and 6 plus. Below is the sample code I used to filling vertex and normal buffer:
-(NSArray*) parseNormalsResource:(NSData*)buffer withPostition:(int)position{
unsigned long count = 0;
int floatSize = sizeof(float);
float *floatNormal=NULL;
int normalCapacity=0;
normalCapacity = getInt32(buffer, &position);
count = (buffer.length-floatSize)/floatSize;
floatNormal = (float*)malloc(normalCapacity * floatSize);
for (int j = 0; j < count; j++){
@autoreleasepool {
float v1 = *(float*)[[buffer subdataWithRange:NSMakeRange(position, floatSize)] bytes];
position = position + floatSize;
floatNormal[j] = v1;
}
}
NSArray *normalResource = @[[NSValue valueWithPointer:floatNormal],[NSNumber numberWithInt:normalCapacity]];
return normalResource;
}
And above whole function runs in background thread and once that is done I assign that vales to NSMutablData object and uses that variable in Open GL for rendering.
self.nonSelectablesNormalsBuffer = [NSMutableData dataWithBytes:[[arrNormals objectAtIndex:0] pointerValue] length:([[arrNormals objectAtIndex:1] intValue]*sizeof(float))];
Please suggest me where I am doing wrong.
Thanks, Devesh