views:

211

answers:

2

Hi,

I have some memory which is initialized in initWithCoder:. I can verify that before the "return self" part of initWithCoder the memory is initialized.

I allocate the memory using malloc and fill it using a custom function:

// in initWithCoder:
fontTexCoords = (GLfloat *)malloc(10 * 8 * sizeof(GLfloat));
[fontInfo textureCoordinatesToArray:fontTexCoords];
NSLog(@"%f", fontTexCoords[0]);  // correctly outputs 1.0

However, in my drawing routine it seems that the contents of that memory has been zeroed:

// in drawView
NSLog(@"%f", fontTexCoords[0]); // incorrectly outputs 0.0

I don't touch the memory in any other place in my application.

Question: why is all the data lost? What process between initWithCoder and drawView goes and does strange things to my malloc'd memory?

Edit:

The output of the first 8 floats in initWithCoder using NSLog(@"initWithCoder: %@ %X %f", self, fontTexCoords, fontTexCoords[0 to 8]);

2009-08-22 21:25:15.220 Memory[32706:20b] initWithCoder: <EAGLView: 0xd19060; frame = (0 0; 320 480); autoresize = W+H; layer = <CAEAGLLayer: 0xd1b300>> D53110 0.000000
2009-08-22 21:25:15.221 Memory[32706:20b] initWithCoder: <EAGLView: 0xd19060; frame = (0 0; 320 480); autoresize = W+H; layer = <CAEAGLLayer: 0xd1b300>> D53110 1.000000
2009-08-22 21:25:15.222 Memory[32706:20b] initWithCoder: <EAGLView: 0xd19060; frame = (0 0; 320 480); autoresize = W+H; layer = <CAEAGLLayer: 0xd1b300>> D53110 0.000000
2009-08-22 21:25:15.223 Memory[32706:20b] initWithCoder: <EAGLView: 0xd19060; frame = (0 0; 320 480); autoresize = W+H; layer = <CAEAGLLayer: 0xd1b300>> D53110 0.500000
2009-08-22 21:25:15.223 Memory[32706:20b] initWithCoder: <EAGLView: 0xd19060; frame = (0 0; 320 480); autoresize = W+H; layer = <CAEAGLLayer: 0xd1b300>> D53110 0.500000
2009-08-22 21:25:15.224 Memory[32706:20b] initWithCoder: <EAGLView: 0xd19060; frame = (0 0; 320 480); autoresize = W+H; layer = <CAEAGLLayer: 0xd1b300>> D53110 0.500000
2009-08-22 21:25:15.224 Memory[32706:20b] initWithCoder: <EAGLView: 0xd19060; frame = (0 0; 320 480); autoresize = W+H; layer = <CAEAGLLayer: 0xd1b300>> D53110 0.500000
2009-08-22 21:25:15.224 Memory[32706:20b] initWithCoder: <EAGLView: 0xd19060; frame = (0 0; 320 480); autoresize = W+H; layer = <CAEAGLLayer: 0xd1b300>> D53110 1.000000

The output from drawView using NSLog(@"drawView: %@ %X %f", self, fontTexCoords, fontTexCoords[0 to 8]);

2009-08-22 21:25:15.399 Memory[32706:20b] drawView: <EAGLView: 0xd19060; frame = (0 0; 320 480); autoresize = W+H; layer = <CAEAGLLayer: 0xd1b300>> D53110 0.000000
2009-08-22 21:25:15.399 Memory[32706:20b] drawView: <EAGLView: 0xd19060; frame = (0 0; 320 480); autoresize = W+H; layer = <CAEAGLLayer: 0xd1b300>> D53110 0.000000
2009-08-22 21:25:15.400 Memory[32706:20b] drawView: <EAGLView: 0xd19060; frame = (0 0; 320 480); autoresize = W+H; layer = <CAEAGLLayer: 0xd1b300>> D53110 0.000000
2009-08-22 21:25:15.401 Memory[32706:20b] drawView: <EAGLView: 0xd19060; frame = (0 0; 320 480); autoresize = W+H; layer = <CAEAGLLayer: 0xd1b300>> D53110 0.000000
2009-08-22 21:25:15.403 Memory[32706:20b] drawView: <EAGLView: 0xd19060; frame = (0 0; 320 480); autoresize = W+H; layer = <CAEAGLLayer: 0xd1b300>> D53110 0.000000
2009-08-22 21:25:15.404 Memory[32706:20b] drawView: <EAGLView: 0xd19060; frame = (0 0; 320 480); autoresize = W+H; layer = <CAEAGLLayer: 0xd1b300>> D53110 0.000000
2009-08-22 21:25:15.404 Memory[32706:20b] drawView: <EAGLView: 0xd19060; frame = (0 0; 320 480); autoresize = W+H; layer = <CAEAGLLayer: 0xd1b300>> D53110 0.000000
2009-08-22 21:25:15.405 Memory[32706:20b] drawView: <EAGLView: 0xd19060; frame = (0 0; 320 480); autoresize = W+H; layer = <CAEAGLLayer: 0xd1b300>> D53110 0.000000

Thanks

+1  A: 

Can you change your NSLog calls to include self in the output? Then confirm that it's the same view that is being used in both places:

NSLog(@"%@ %f", self, fontTexCoords[0]);
Jason
Yes it's the same object
rein
A: 

Found the problem. It was my stupidity. I was freeing the memory in the wrong method. Somehow I put the free(fontTexCoords) in layoutView instead of dealloc.

Silly, silly me :)

rein