Jump to content

  • Log In with Google      Sign In   
  • Create Account


app crashes when binding buffers and call draw function


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 Prognatus   Members   -  Reputation: 198

Like
0Likes
Like

Posted 12 July 2013 - 12:29 PM

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

}

Sponsor:

#2 Prognatus   Members   -  Reputation: 198

Like
0Likes
Like

Posted 12 July 2013 - 01:48 PM

When i try to debug the program i get Access violation reading location 0x00000000.

#3 mhagain   Crossbones+   -  Reputation: 7344

Like
0Likes
Like

Posted 12 July 2013 - 02:10 PM

How are you loading function pointers for functionality greater than GL 1.1?


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#4 Prognatus   Members   -  Reputation: 198

Like
0Likes
Like

Posted 12 July 2013 - 03:25 PM

im using the libary's glew and glfw.

#5 mhagain   Crossbones+   -  Reputation: 7344

Like
0Likes
Like

Posted 12 July 2013 - 04:21 PM

And are you remembering to call glewInit?  And doing so after you create your window and GL context?  And on hardware that supports buffer objects?


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#6 Prognatus   Members   -  Reputation: 198

Like
0Likes
Like

Posted 12 July 2013 - 05:47 PM

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.

#7 Chananya Freiman   Members   -  Reputation: 140

Like
1Likes
Like

Posted 12 July 2013 - 05:56 PM

Sorry if this offends you, but it's crashing because there is hardly one line of code there that isn't an error.

I'll add a full reply once I get back to my computer if nobody answers by then.



#8 MarkS   Prime Members   -  Reputation: 875

Like
0Likes
Like

Posted 12 July 2013 - 06:41 PM

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, 12 July 2013 - 06:46 PM.


#9 mhagain   Crossbones+   -  Reputation: 7344

Like
2Likes
Like

Posted 12 July 2013 - 07:13 PM

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, 12 July 2013 - 07:13 PM.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS