# Normal Pointer Array Size

• 06-09-2009, 04:08 AM
NikLever
Normal Pointer Array Size
Hi
Here is a strange one.
I am developing a iPhone 3D engine and have a question about the normal pointer array.

If I create an array that is the same size as the vertex array then my app crashes. If I make it double the size then all is OK. Can anyone explain this behaviour?

...
vertices = new GLfloat[numvertices * 3];
normals = new GLfloat[numvertices * 6];//Using 3, 4 or 5 the app crashes
glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_NORMAL_ARRAY );
glVertexPointer( 3, GL_FLOAT, 0, vertices );
glNormalPointer( GL_FLOAT, 0, normals );
...

...
vertices[id] = pt->x; vertices[id] = pt->x; vertices[id] = pt->x;
normals[id] = normal->x; normals[id] = normal->x; normals[id] = normal->x;
id += 3;
...

...
glDrawArrays( GL_TRIANGLES, 0, id );

Cheers Nik
• 06-09-2009, 09:57 AM
niallm
Re: Normal Pointer Array Size
Maybe I'm looking at it wrong, but shouldn't the last parameter to glDrawArrays() be the number of vertices you want to draw, not the number of elements in your vertex array?

For example: glDrawArrays( GL_TRIANGLES, 0, numvertices );
• 06-10-2009, 09:32 AM
NikLever
Re: Normal Pointer Array Size
I understand - since a normal is 3 floats and my vertices use 3 floats in the call to glVertexPointer. The value count in the call to glDrawArrays is how many vertices to draw ie in my code (id/3), not always numvertices this is simply the size of the biggest mesh. I amended the code and all is working fine. I should have sussed this but thanks for the advice it was driving me mad.