Jump to content
  • Advertisement
Sign in to follow this  
Mantear

glBufferDataARB with size 0

This topic is 4862 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!