Jump to content
  • Advertisement
Sign in to follow this  
Silex

VBOs cause seg fault?

This topic is 4829 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'm trying to implement vertex buffer objects but they seg fault when I trying to generate them. Below is my mesh class which handles all that. If I disable VBO support the mesh will render fine using regular vertex arrays. Can anyone spot what's wrong?
#include <GL/gl.h>
#include <GL/glu.h>
#include "glext.h"

PFNGLGENBUFFERSARBPROC glGenBuffersARB=0;
PFNGLBINDBUFFERARBPROC glBindBufferARB=0;
PFNGLBUFFERDATAARBPROC glBufferDataARB=0;
PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB=0;

#define BUFFER_OFFSET(i) ((float*)NULL + (i))

mesh::mesh() : verts(0), norms(0), VBO_loaded(false)
{
}

mesh::~mesh()
{   if (verts) delete [] verts; verts=0;
    if (norms) delete [] norms; norms=0;
    if (VBO_loaded)
    {   unsigned int buffers[2] = {VBO_verts, VBO_norms};
        glDeleteBuffersARB(2, buffers);
    }
    if (VBO_verts) glDeleteBuffersARB(1, &VBO_verts);
    if (VBO_norms) glDeleteBuffersARB(1, &VBO_norms);
}

int mesh::draw(void)
{   glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);   

    if (VBO_loaded)
    {   glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBO_verts);
        glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));
        glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBO_norms);
        glNormalPointer(GL_FLOAT, 0, BUFFER_OFFSET(0));
    }
    else
    {   glVertexPointer(3, GL_FLOAT, 0, verts);
        glNormalPointer(GL_FLOAT, 0, norms);
    }

    glDrawArrays(GL_TRIANGLES, 0, num_faces*3);

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
}

int mesh::loadVBO(void)
{   //generate and bind the vertex buffer
    glGenBuffersARB(1, &VBO_verts);
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBO_verts);
    //load the data
    glBufferDataARB(GL_ARRAY_BUFFER_ARB, num_faces*3*sizeof(float),
                    verts, GL_STATIC_DRAW_ARB);

    //generate and bind the normal buffer
    glGenBuffersARB(1, &VBO_norms);
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBO_norms);
    //load the data
    glBufferDataARB(GL_ARRAY_BUFFER_ARB, num_faces*3*sizeof(float),
                    norms, GL_STATIC_DRAW_ARB);

    //geometry is now stored on video card ram, delete temporary copies
    if (verts) delete [] verts; verts=0;
    if (norms) delete [] norms; norms=0;
    VBO_loaded=true;
}

Share this post


Link to post
Share on other sites
Advertisement
before, I didn't. now, like this:


if (!glGenBuffersARB)
glGenBuffersARB=(PFNGLGENBUFFERSARBPROC)SDL_GL_GetProcAddress("glGenBuffersARB");
if (!glBindBufferARB)
glBindBufferARB=(PFNGLBINDBUFFERARBPROC)SDL_GL_GetProcAddress("glBindBufferARB");
if (!glBufferDataARB)
glBufferDataARB=(PFNGLBUFFERDATAARBPROC)SDL_GL_GetProcAddress("glBufferDataARB");
if (!glDeleteBuffersARB)
glDeleteBuffersARB=(PFNGLDELETEBUFFERSARBPROC)SDL_GL_GetProcAddress("glDeleteBuffersARB");




Now I can load the mesh into the VBO's without seg faults, but now it seg faults when it gets to the drawing routine. oddly though it doesn't seg fault until after it gets through it twice...ideas?

Share this post


Link to post
Share on other sites
EXACTLY the same problem (vbos, second render call, etc) on Linux with NVIDIA 71.74 drivers. Is this the configuration that you're using (or similar)?

I'm 99% certain that what I'm seeing at least is a driver bug, as it ONLY occurs when using a static vertex buffer AND a static/dynamic index buffer (any other combination of host/static/dynamic does not cause the problem) and ONLY on Linux with NVIDIA cards (I've not yet had time to try a differrent driver version).

Is this your experience as well?

Share this post


Link to post
Share on other sites
yes, linux and NVIDIA.

either we're both doing something wrong or NVIDIA has work to do. ~_~

Share this post


Link to post
Share on other sites
Quote:
Original post by Silex
yes, linux and NVIDIA.

either we're both doing something wrong or NVIDIA has work to do. ~_~

Have you tried with the latest drivers? I haven't had the chance to but I was hoping (perhaps naively) that they'd fix it. Otherwise I should get around to writing up a short test case and sending it to them.

In any case, try switching to a dynamic vertex buffer (just change the hint). It'll be slower but it works for me at least.

[Edited by - AndyTX on July 27, 2005 3:19:35 PM]

Share this post


Link to post
Share on other sites
Alright I'll see about writing up a small test case and sending it to NVIDIA to look at shortly. Does using a dynamic VBO fix it in the mean time (as it does for me)?

Share this post


Link to post
Share on other sites
You mean changing the fourth argument of glBufferDataARB to GL_DYNAMIC_DRAW_ARB?

That didn't fix it for me, same problem.

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!