glBufferDataARB with size 0

Started by
0 comments, last by Yann L 18 years, 4 months ago
I ran across something interesting when converting from MSVC6 to 8. I used to bind some VBOs and update their data via glBufferDataARB() with a size of 0 (never did a check on the size, just updated it regardless). Now, in MSVC6, it accepted it just fine. But in 8, I got errors in the std::vector implementation (the data I'm binding to the VBO buffer is in a std::vector). Here's the line:
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER, m_VertexIndex.size() * sizeof(unsigned int), &m_VertexIndex[0], GL_DYNAMIC_DRAW);
To get around this, I simply don't bind the data if the size is 0. What could have caused this difference?
Advertisement
If size() is zero, then the behaviour of &m_VertexIndex[0] is undefined. It could actually lead to a NULL pointer dereference, or worse.

It's not surprising that VC6 didn't complain - VC6 is a, well, very bad quality compiler (read: complete crap). VC8 is not, and correctly identifies the dangerous construct. And BTW, this has nothing to do with VBOs or glBufferDataARB. It's just that the [0] index into your vector accesses the first element - ie. assumes that there is in fact at least one element.

This topic is closed to new replies.

Advertisement