I'm trying to make my code work with pointers, but can't find what is wrong. The first one is working correctly, with global variable declared with the size of the array. The second one are pointers, and can't find what is wrong, because i get no errors, the drawing is just not done.
Why don't you switch to std::vector which will handle all memory automatically?
If performance is an issue, you can pre-allocate the vector with a given capacity. But even then, if you by accident put more elements in it, it will grow automatically for you.
Why don't you switch to std::vector which will handle all memory automatically?
If performance is an issue, you can pre-allocate the vector with a given capacity. But even then, if you by accident put more elements in it, it will grow automatically for you.
I didnt switch to vector since i don't know how they will work with Opengl. If it doesn't work with normal array, i'll probably have to switch. How could i handle all memory at once from the text file?
Also, i think the problem is coming from sizeof(g_vertices) in the bindbuffer function
Last edited by m_power_hax; December 20th, 2010 at 07:46 AM.
While the above is true, note that you need to special-case if g_vertices.empty(), since in that case accessing g_vertices[0] may throw an exception on some compilers under some configurations. Alternatively you could always resize the vector 1+ what you actually need so that it is never empty.
While the above is true, note that you need to special-case if g_vertices.empty(), since in that case accessing g_vertices[0] may throw an exception on some compilers under some configurations. Alternatively you could always resize the vector 1+ what you actually need so that it is never empty.
Yes. Note, that for the pointer solution you would need a similar check on pointer != NULL.
In that particular case I would not expect a problem since the sizeof would be evaluated at compile time anyway.
I would argue any implementation of a function taking a pointer and a size which did *anything* with the pointer when a size of 0 is specified would be wrong. The issue in the case of a vector is not the function call, but getting the pointer in the first place.
Bookmarks