(Edited)
I thought the problem was in NULL
being passed as indices
parameter to glDrawElements()
here:
glDrawElements(elementType, elements * verticesPerElement,
GL_UNSIGNED_INT, (void*) 0);
The last parameter, indices
, used to be mandatory and passing in 0
or NULL
wouldn't work, because it would then try to read the indices from that address and would produce that error Access violation reading location 0x00000000.
But as Jherico pointed out, it is possible to have a buffer with indices bound to GL_ELEMENT_ARRAY
and then the indices
parameter is an offset into that buffer, not a pointer. Passing 0 then simply means 'no offset'. And Oculus Rift SDK apparently uses this method.
The program crashing with that invalid access to address 0x0 at the line with glDrawElements()
therefore does not indicate that 0
should not be used, but that the GL_ELEMENT_ARRAY
buffer is not initialized or enabled correctly. Probably because of an improper cleanup, as Jherico pointed out in his better answer.