VBOs cause seg fault?

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

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()
{   if (verts) delete [] verts; verts=0;
if (norms) delete [] norms; norms=0;
{   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);

{   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);
}

{   //generate and bind the vertex buffer
glGenBuffersARB(1, &VBO_verts);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBO_verts);
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);
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;
}



Share on other sites
how do you initalise the pointers to the extension's functions?

Share on other sites
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 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 on other sites
yes, linux and NVIDIA.

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

Share on other sites
Quote:
 Original post by Silexyes, 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 on other sites
I'll try the latest nvidia driver now...

Share on other sites
latest drivers didn't fix it for me

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 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.

• Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 13
• 9
• 11
• 15