finicky new operator

Started by
11 comments, last by GameDev.net 18 years, 4 months ago
Quote:Original post by Aryabhatta
Your problem could be with this line of code:

n->vert_array[pos*9+i] = arr;

what values does pos*9 + i take?

vert_array is an array of GLFloats. The size of the array is 9.
You might be accessing memory locations way beyond the bounds of the array.

Also you are sure it is the new Glfloat.. line which is causing the problem?

Did you try turning optimizations off and debugging this on a debug version?


pos is the number of faces, and helps me with finding the last elements of the array. when its multiplied by 9 (3 vertices with 3 values (x, y, z)) it gives the proper offset with pos. i is just an iterator.

arr is always an array with 9 GLfloats in it.

when i run it pos is correct.

i also have all optimizations off.

i guess im going to try and do everything in std::vector and then when its done ill pass everything in a dynamic array and then into the vertex array.
Advertisement
Quote:Original post by adam17
arr is always an array with 9 GLfloats in it.


Yes, and so is n->vert_array. Scroll back up and reread d00fus' post. The 'new' does not expand an existing array allocation; it replaces it (rather, it causes the pointer to point at a new allocation, and the old allocation is forgotten about. So not only do you still have 9 elements, you also have a memory leak.) If pos is anything greater than 0, then you create an array index >= 9, and use it for a 9-element array - boom.
check that 'n' is valid.

This topic is closed to new replies.

Advertisement