Jump to content
  • Advertisement
Sign in to follow this  
pieslice

OpenGL Null-pointer crash when using VBOs

This topic is 3703 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've ran into very strange problem with my OpenGL application. I get occasional null-pointer crashes when I'm trying to draw geometry stored as VBO. I assume vboHandle is correct, as it won't assert. All geometry loads fine and every model is drawn nicely, but on certain occasions (depends on the phase of the moon) the program will crash to the glInterleavedArrays call.
        //draw vbo object
        VertexBufferObject::EnableBuffer( vboHandle );
        
        glInterleavedArrays( GL_T2F_N3F_V3F, 0, 0 ); //this line crashes
        
        glDrawArrays( GL_TRIANGLES, 0, vertexCount );
        VertexBufferObject::DisableVBORendering();

        GameDataContainer::AddPolysRendered( vertexCount / 3 );
I am also experiencing strange behaviour in my application when I don't use the VBO drawing. The GL_COLOR_ARRAY client state seems to set itself enabled and corrupt graphics. It's definitely not set enabled by glEnableClientState call, and I am currently using the kludge solution to disable the GL_COLOR_ARRAY by glDisableClientState. I've been experiencing these problems when I updated my gfx card drivers (I have GF6600GT) about a month ago, so I assume this can be a driver bug too.

Share this post


Link to post
Share on other sites
Advertisement
NP in a fundamental extension, under NVIDIA public release drivers on a modern GPU. Highly doubt it's a driver bug [smile]

The most common cause is vertexCount > than the number of elements in the buffer.
Put some asserts in, e.g.

assert(type == GL_TRIANGLE)
assert(vertexCount == sizeof(VBOSourceData)/sizeof(Vertex))

might help you narrow down the problem.

[EDIT:could maybe, your video card be overheating / dying?]

Share this post


Link to post
Share on other sites
Try replacing glInterleavedArrays( GL_T2F_N3F_V3F, 0, 0 );
with the equivalent gl****Pointer calls.
glInterleavedArrays is rarely used.

Share this post


Link to post
Share on other sites
Quote:
Original post by silvermace
[EDIT:could maybe, your video card be overheating / dying?]


I highly doubt this is the case because the crash is consistent, it happens on exactly same spot every time and when I put the exactly same data with basic vertex arrays it works fine. But I want to use the VBOs as they really increase the overall performance.

The draw order of the elements in the render queue seems to have something to do with the crash as altering the draw order changes the crash point. But it is still consistent.

Quote:
Original post by V-man
Try replacing glInterleavedArrays( GL_T2F_N3F_V3F, 0, 0 );
with the equivalent gl****Pointer calls.
glInterleavedArrays is rarely used.


Thanks. I'll try this out even if the replacement like this does sound like a voodoo magic trick to me ;)

I just used glInterleavedArrays because I wanted to reduce the count of the overall VBO objects.

Share this post


Link to post
Share on other sites
No it's no voodoo ;)

Instead of calling glInterleavedArrays that takes one array and one of a set of fixed formats you can point OpenGL to the individual arrays.

AFAIK glInterleavedArrays( GL_T2F_N3F_V3F, 0, 0 ); would be something like:

glTexcoordPointer(2, GL_FLOAT, 32, 0); //2 float texture coords (u + v), offset by 32 bytes, starting at byte 0
glNormalPointer(GL_FLOAT, 32, 0 + 8); //a normal (floats), offset by 32 bytes, starting at byte 8
glVertexPointer(3, GL_FLOAT, 32, 0 + 20); //3 float vertex coords (x, y, z), offset by 32 bytes, starting at byte 20

The size of one vertex is 32 bytes: 2 texcoords (8 bytes), a normal (12 bytes) and the vertex coords (12 bytes). Thus each element in the array starts at multiples of 32: 0, 32, 64, 96, ...
The last argument is the offset into the array.

If you had muliple arrays you could have used

glTexcoordPointer(2, GL_FLOAT, 0, 0);
glNormalPointer(GL_FLOAT, 0, 0);
glVertexPointer(3, GL_FLOAT, 32, 0);

and bind another VBO before each call to glXxxxxPointer.

The beauty of this approach is the flexibility. You can use different vertex layouts, distinct arrays, omit components etc.

Share this post


Link to post
Share on other sites
Putting the components into distinct VBOs seemed to fix the crash. Thanks a lot for your help!

But I'm still puzzled what was wrong with glInterleavedArrays?

Share this post


Link to post
Share on other sites
Quote:
Original post by pieslice

I am also experiencing strange behaviour in my application when I don't use the VBO drawing. The GL_COLOR_ARRAY client state seems to set itself enabled and corrupt graphics. It's definitely not set enabled by glEnableClientState call, and I am currently using the kludge solution to disable the GL_COLOR_ARRAY by glDisableClientState.


Just noticed that it seems that the glInterleavedArrays messes up the color array bit, which was causing this behaviour

Share this post


Link to post
Share on other sites
Quote:
Original post by pieslice
Putting the components into distinct VBOs seemed to fix the crash.

You generally should not do that. Interleaving the data is often much faster. But don't use glInterleavedArrays.

Quote:
Original post by pieslice
But I'm still puzzled what was wrong with glInterleavedArrays?

It's old. It's obsolete. Noone ever uses it.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!