Sign in to follow this  
Prognatus

app crashes when binding buffers and call draw function

Recommended Posts

Prognatus    198
code seems to crash when i call my make_buffer function or my render function.


void Graphics::make_buffer(GLenum object, GLenum type)
{
int offset = object * numperobj;
glGenBuffers(1, buf.buffer);
glBindBuffer(GL_ARRAY_BUFFER, buf.buffer[Vertices+ offset]);
glBufferData(GL_ARRAY_BUFFER, sizeof(floorverts), floorverts, GL_STATIC_DRAW);
glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));
glEnableClientState(GL_VERTEX_ARRAY);

glGenBuffers(1, buf.buffer);
glBindBuffer(GL_ARRAY_BUFFER, buf.buffer[Colors + offset]);
glBufferData(GL_ARRAY_BUFFER, sizeof(floorcol), floorcol, GL_STATIC_DRAW);
glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));
glEnableClientState(GL_COLOR_ARRAY);

glGenBuffers(1, buf.buffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf.buffer[Elements + offset]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(floorinds), floorinds, GL_STATIC_DRAW);

glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

buf.PrimType[object] = type;
buf.NumElems[object] = sizeof(floorinds);
}


void Graphics::render(GLuint object)
{
int offset = object * numperobj;
glBindBuffer(GL_ARRAY_BUFFER, buf.buffer[Vertices + offset]);
glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));
glEnableClientState(GL_VERTEX_ARRAY);

glBindBuffer(GL_ARRAY_BUFFER, buf.buffer[Colors + offset]);

glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));
glEnableClientState(GL_COLOR_ARRAY);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf.buffer[Elements + offset]);

glDrawElements(buf.PrimType[object], buf.NumElems[object], GL_UNSIGNED_INT, BUFFER_OFFSET(0));

}

Share this post


Link to post
Share on other sites
Prognatus    198
yes i called glewinit() after i created my window and made the window context. I dont know if it supports buffer objects but my graphics card is 330m nvidia.

Share this post


Link to post
Share on other sites
MarkS    3502
Here is a big problem and most likely the source of your problems:
 

..snip..
glGenBuffers(1, buf.buffer); // You allocate a single buffer here.
glBindBuffer(GL_ARRAY_BUFFER, buf.buffer[Vertices+ offset]); // And then access it like an array here.
..snip..
}


If "buf.buffers" is an array, then you need to tell glGenBuffers how many buffers to generate. You are currently telling it to create one buffer, and then you access it like an array of buffers.

Also, you need a separate buffer for each array. One for "GL_VERTEX_ARRAY", one for "GL_COLOR_ARRAY" and one for "GL_ELEMENT_ARRAY". You are calling glGenBuffers three times in a row on the same buffer, thereby overwriting the buffer. At the end of your "make_buffer" function, only the element buffer exists. Edited by MarkS

Share this post


Link to post
Share on other sites
mhagain    13430

Actually an "Access violation reading location 0x00000000" in the debugger most likely means a NULL function pointer, which is most likely that for glGenBuffers (the rest will also be NULL but glGenBuffers is just the first one hit), which means that either glewInit failed, or was called in the wrong order (which the OP has confirmed didn't happen) or the hardware doesn't support buffer objects.

 

It would have helped if the OP had stated which line the program crashed on too, but I'm going to make a guess despite that.

 

I see from e.g. http://forums.steampowered.com/forums/showthread.php?t=1733353 that the NVIDIA 330M is an Optimus card, so my betting is that this program is running on the Intel and that the Intel has an OEM driver with no OpenGL support.

 

The rest of the code, as pointed out by the other replies, also needs fixing.

Edited by mhagain

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this