Re: odd problems with NSData / OpenGL
Re: odd problems with NSData / OpenGL
- Subject: Re: odd problems with NSData / OpenGL
- From: David Duncan <email@hidden>
- Date: Tue, 08 Dec 2009 15:59:12 -0800
If you don't turn GC on, then you likely don't have it on. Check your
project settings, as most if the project templates do not enable GC.
--
David Duncan @ My iPhone
On Dec 8, 2009, at 3:52 PM, Henri Häkkinen <email@hidden>
wrote:
On Dec 8, 2009, at 6:42 PM, David Duncan wrote:
More than likely this is a memory management problem. Specifically,
you probably aren't claiming ownership of the NSData object that
you store in your instance variable, and thus it is being
deallocated out from under you.
I was under the impression that automatic garbage collection was
used in Mac OS X 10.5 and over, so retaining and releasing objects
was handled automatically?
This is the initializer method of my Mesh class (I'm using OpenCTM
library for importing triangle meshes):
- (id)initWithContentsOfFile:(NSString *)path
{
self = [super init];
if (self) {
// Create an OpenCTM context and load the mesh from disk.
CTMcontext context = ctmNewContext(CTM_IMPORT);
ctmLoad(context, [path UTF8String]);
// Check OpenCTM errors.
CTMenum error = ctmGetError(context);
if (error != CTM_NONE) {
NSLog(@"OpenCTM error while opening %@: %s (%d)", path,
ctmErrorString(error), error);
ctmFreeContext(context);
[self dealloc];
return nil;
}
// Store the geometry arrays.
_vertices = [NSData dataWithBytes:ctmGetFloatArray(context,
CTM_VERTICES)
length:ctmGetInteger(context,
CTM_VERTEX_COUNT) * sizeof(CTMfloat[3])];
_indices = [NSData dataWithBytes:ctmGetIntegerArray(context,
CTM_INDICES)
length:ctmGetInteger(context,
CTM_TRIANGLE_COUNT) * sizeof(CTMuint[3])];
// Calculate the bounding sphere radius.
for (CTMuint i = 0; i < ctmGetInteger(context,
CTM_VERTEX_COUNT) * 3; i += 3) {
const CTMfloat x = ctmGetFloatArray(context, CTM_VERTICES)
[i + 0];
const CTMfloat y = ctmGetFloatArray(context, CTM_VERTICES)
[i + 1];
const CTMfloat z = ctmGetFloatArray(context, CTM_VERTICES)
[i + 2];
_radius = MAX(sqrt(x*x + y*y + z*z), _radius);
}
// Release the OpenCTM context.
ctmFreeContext(context);
}
return self;
}
--
David Duncan
Apple DTS Animation and Printing
Regards,
Henri Häkkinen
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden