PDA

View Full Version : DisplayList (GL_COMPILE crash on glDrawElements)



jsmithown
10-28-2010, 09:25 AM
I wrote some code that utilizes VBOs. It works fine by itself, but it crashes whenever I try to adapt it to a DisplayList. I'll post the relevant code and hopefully someone will see a smoking gun!

It only seems to crash if I include the glDrawElements() in the compiling of the displaylist. But, I don't see why it would, since displaylist supports it and it works in the non-displaylist mode.

Construct VBO


const int VBO_BUFF_SIZE = 4*1024*1024; //4MB

//Create a STATIC VBO reference
glGenBuffers(1, &VertexVBO_ID);
glBindBuffer(GL_ARRAY_BUFFER, VertexVBO_ID);
//Create the VBO buffer with nothing in it
glBufferData(GL_ARRAY_BUFFER, VBO_BUFF_SIZE, NULL, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(V3)*g_vertexCount, &vertices[0].x);

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(V3), BUFFER_OFFSET(0));
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(V3), BUFFER_OFFSET(48));

glGenBuffers(1, &IndexVBO_ID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexVBO_ID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, VBO_BUFF_SIZE, NULL, GL_STATIC_DRAW);
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(unsigned short)*g_indexCount, &indices[0]);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexVBO_ID);


Draw VBO (working)


//Clear color - clears frame buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLoadIdentity(); gluLookAt(eyeX,bounds,eyeZ,centerX,centerY,centerZ ,upX,upY,upZ);
//glRotatef(90,0,0,1.0f);
glDrawElements(GL_QUADS, g_indexCount, GL_UNSIGNED_SHORT, BUFFER_OFFSET(0)); //The starting point of the IBO
glutSwapBuffers();


Draw VBO (displaylist, crashing)


list_ID = glGenLists(1);
glNewList( list_ID, GL_COMPILE );

//Clear color - clears frame buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLoadIdentity(); gluLookAt(eyeX,bounds,eyeZ,centerX,centerY,centerZ ,upX,upY,upZ);
//glRotatef(90,0,0,1.0f);
glDrawElements(GL_QUADS, g_indexCount, GL_UNSIGNED_SHORT, BUFFER_OFFSET(0));
glutSwapBuffers();

glEndList()

Crashes on this line:
glDrawElements(GL_QUADS, g_indexCount, GL_UNSIGNED_SHORT, BUFFER_OFFSET(0));

mfort
10-28-2010, 09:54 AM
Read OpenGL specification. It crashes simply because it is not allowed (dereferences buffer). Also SwapBuffers in display list is not allowed.

jsmithown
10-28-2010, 12:08 PM
Ahh I didn't pick up on that. I modified the code to stop dereferencing the buffer and it worked. Thanks a lot!