• Advertisement

Let's take a step back, shall we?

This topic is 4729 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

Ok, so as many (if not all of you know), I'm having an absolutely wonderful time with my vertex buffer objects (sarcasm). So in attempting to find out why things are blowing up on me, I thought I'd check to make sure that everything involved with the VBOs are set up properly. Well, after a few hours of checking this and that, I thought "hey, take the VBO out and see if everything works client side." So, I set the condition to use the VBO or not to false and just used a regular VA with glDrawRangeElements and it started crashing too. That really got me wondering what was going on. So, I cut it down to just a single call to glDrawElements and as it's still crashing, I'm thinking there has to be something wrong. Here's what I'm left with:
glNormalPointer(GL_FLOAT, sizeof(*vertList), &vertList[0].norm);
glVertexPointer(3, GL_FLOAT, sizeof(*vertList), &vertList[0].vert);
glDrawElements(GL_TRIANGLES, numInd, GL_UNSIGNED_INT, index);


When the program is run, the value of numInd is 36, and index contains the following:
0
1
2
1
3
2
4
5
6
5
7
6
17
23
14
24
20
15
11
29
18
30
25
19
8
26
12
27
31
13
16
21
9
22
28
10


That's 36, perfectly valid indices, ranging from 0 to 31 (and there just so happens to be 32 elements to vertList). Index array is a list of unsigned int and I give it enough space for 3 * the size of an unsigned int * the number of faces there are. vertList contains 32 valid vectors and normals (I had both output to a file and checked it). I've also remembered to enable both GL_NORMAL_ARRAY and GL_VERTEX_ARRAY. So! Am I crazy or shouldn't at least this work? Or both? Upon execution, I get the following error: Unhandled exception at 0x04e462aa in project3.exe: 0xC0000005: Access violation reading location 0x09b8abe0. Can anybody see what's going on here? I'm happy to provide more info if it will help.

Share this post

Share on other sites
Advertisement
You are, without a doubt accessing a bogus entry into some array.
ensure that you're not reading doubles when you should be reading floats, your stride in the data arrays is correct (if any), you aren't setting some other data array, etc...

You do realize that you're passing a stride to your gl*Pointer calls.
are you sure this is correct? Your arrays don't seem to be interleaved if you're passing both a vertex and normal pointer.

Try setting that sizeof() to 0.

Share this post

Share on other sites
Oops, false alarm. I was still binding the VBOs when I was trying that. Commenting them out I was able to use glDrawElements just fine. That kind of tells me that there's something indeed wrong with the way I'm doing the VBOs.

What if I didn't want to use any VBOs? Would I just do a glBindBufferARB(GL_ARRAY_BUFFER_ARB, NULL);?

Share this post

Share on other sites
Quote:
 Original post by AelunedYou do realize that you're passing a stride to your gl*Pointer calls.are you sure this is correct? Your arrays don't seem to be interleaved if you're passing both a vertex and normal pointer.

Actually they are interleaved. They're stored together within the same struct in a list of that struct. By setting the stride to the size of the struct and having each pointing to the first element's corresponding field, the interleaved array draws properly.

Now if I could only figure out what was wrong with my damn VBOs...

Share this post

Share on other sites
Yes, that's how you would unbind the VBO.
You're not doing anything wrong, that's perfectly normal.

If you have a currently bound VBO it will be the one used to render primitives.
If your glDraw* call steps out of the bound VBOs limits, boom. (just like you saw).

Share this post

Share on other sites
not sure about sizeof(*vertList),
won't that return the size of what it points to - namely a float, I think the size of the array is
numElements*sizeof(*vertList).

Share this post

Share on other sites
ok, I use vbos in a similar way:

Here's how I set them up:

//ON CREATING THE VBOS
---------------------------------------------------
// Generate And Bind The Vertex Buffer
glGenBuffersARB( 1, &vboVertexData );
glBindBufferARB( GL_ARRAY_BUFFER_ARB , vboVertexData); // Bind The Buffer
glBufferDataARB( GL_ARRAY_BUFFER_ARB , MAP_X*MAP_Z*3*sizeof(float),
m_terrain, GL_STATIC_DRAW_ARB );

// Generate And Bind The normlas Buffer
glGenBuffersARB( 1, &vboNormalsData );
glBindBufferARB( GL_ARRAY_BUFFER_ARB , vboNormalsData); // Bind The Buffer
// Load The Data
glBufferDataARB( GL_ARRAY_BUFFER_ARB , MAP_X*MAP_Z*3*sizeof(float),
m_normalArray, GL_STATIC_DRAW_ARB );
---------------------------------------------------
ON USING THE VBOS TO DRAW:

glBindBufferARB( GL_ARRAY_BUFFER_ARB , vboVertexData );
glVertexPointer( 3, GL_FLOAT, 0, NULL);
glBindBufferARB( GL_ARRAY_BUFFER_ARB , vboNormalsData );
glNormalPointer(GL_FLOAT, 0, NULL);

//DID YOU DO THIS BIT HERE ?
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);

//DRAW ELEMENTS
glDrawElements(GL_TRIANGLE_STRIP, Length, GL_UNSIGNED_INT,
(const void *)DataPointer);

Hope this helps

Share this post

Share on other sites
Thank you for your response, ade-the-heat. And everyone else as well. Last night our local expert _the_phantom_ found the problem with my VBOs: I wasn't declaring a stride size for my interleaved array when calling the gl*Pointer() functions. They're working now, but they're incredibly slow. I'll be investigating that (and likely posting a question or two) this morning.

Thanks again everyone!

Share this post

Share on other sites

• Advertisement
• Advertisement
• Popular Tags

• Advertisement
• Popular Now

• 45
• 11
• 17
• 11
• 13
• Advertisement