PDA

View Full Version : Access Violation in glMultiDrawElements ?



sdprtf
03-13-2009, 02:28 AM
Hey guys!
While reading the 'red book',the code "mvarray.c"


static GLint vertices[] = {25, 25,
75, 75,
100, 125,
150, 75,
200, 175,
250, 150,
300, 125,
100, 200,
150, 250,
200, 225,
250, 300,
300, 250};

glEnableClientState (GL_VERTEX_ARRAY);
glVertexPointer (2, GL_INT, 0, vertices);
static GLubyte oneIndices[] = {0, 1, 2, 3, 4, 5, 6};
static GLubyte twoIndices[] = {1, 7, 8, 9, 10, 11};
static GLsizei count[] = {7, 6};
static GLvoid * indices[2] = {oneIndices, twoIndices};

glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glMultiDrawElements (GL_LINE_STRIP, count, GL_UNSIGNED_BYTE,
indices, 2); glFlush ();

there is an Access Violation in glMultiDrawElements.
while debuging it shows "unhandled exception in mvarray.exe : 0xc0000005 :Access Violation ".
but when its equal form:


int i;
for (i = 0;i < 2;i++)
{
if (count[i] > 0)
{
glDrawElements(GL_LINE_STRIP,count[i],GL_UNSIGNED_BYTE,indices[i]);
}
}

it works just fine.
I use VC6 under WinXP.
so pls tell me why?
thx!

scratt
03-13-2009, 04:06 AM
I suspect something is wrong with your pointer to the count array, or the pointer to pointers array. I tend to use actual pointers, or reference arrays as &array[0] in GL calls.

Perhaps see if that solves it.

The crash you are getting certainly seems like one where GL is accessing somewhere it shouldn't with an invalid pointer...

sdprtf
03-13-2009, 05:54 AM
Problem solved!