Craxic's picture

GL.DrawElements AccessViolationException

Having some trouble here. I've been trying to figure out what the hell is going on for hours, so it's time to bring in the big guns (that's you :) )

            GL.BindBuffer(BufferTarget.ArrayBuffer, verts.GetVBO());
 
            //Print contents
            IntPtr ptr = GL.MapBuffer(BufferTarget.ArrayBuffer, BufferAccess.ReadOnly);
            unsafe
            {
                float* f = (float*)ptr;
                for (int i = 0; i < verts.GetVertCount(); i++)
                {
                    Console.WriteLine("U: " + f[i * 5]);
                    Console.WriteLine("V: " + f[i * 5 + 1]);
                    Console.WriteLine("X: " + f[i * 5 + 2]);
                    Console.WriteLine("Y: " + f[i * 5 + 3]);
                    Console.WriteLine("Z: " + f[i * 5 + 4]);
                }
            }
            GL.UnmapBuffer(BufferTarget.ArrayBuffer);
            //Describe format
            GL.InterleavedArrays(InterleavedArrayFormat.T2fV3f, 0, IntPtr.Zero);
 
            for (int i = 0; i < indices.Length; i++)
            {
                Console.WriteLine("Index " + i + " " + indices[i]);
            }
 
            Debug.Post("model", "Drawing: " + IBOHandle + " " + verts.GetVBO());
            GL.DrawElements(DrawType, indices.Length, DrawElementsType.UnsignedInt, indices);

Pretty simple stuff, we just map the VBO, print its contents and print the contents of the indices. Then, we draw the simple quad.... wait no. We don't. We crash.
Output:

U: 0
V: 0
X: -1
Y: -1
Z: 0
U: 1
V: 0
X: 1
Y: -1
Z: 0
U: 1
V: 1
X: 1
Y: 1
Z: 0
U: 0
V: 1
X: -1
Y: 1
Z: 0
Index 0 0
Index 1 1
Index 2 2
Index 3 0
Index 4 2
Index 5 3
[MODEL] Drawing: 6 5

To make matters worse, the draw operation fails after a few successful ones, all of which print the same, expected, output.

I've replaced

            GL.InterleavedArrays(InterleavedArrayFormat.T2fV3f, 0, IntPtr.Zero);

with

GL.EnableClientState(ArrayCap.VertexArray);
GL.EnableClientState(ArrayCap.TextureCoordArray);
GL.VertexPointer(3, VertexPointerType.Float, VertexPT.SizeInBytes, 0);
GL.TexCoordPointer(2, TexCoordPointerType.Float, VertexPT.SizeInBytes, (IntPtr)(3 * sizeof(float)));

to no avail. No other ArrayCaps are enabled. I even went so far as to:

GL.DisableClientState(ArrayCap.ColorArray);
GL.DisableClientState(ArrayCap.EdgeFlagArray);
GL.DisableClientState(ArrayCap.FogCoordArray);
GL.DisableClientState(ArrayCap.IndexArray);
GL.DisableClientState(ArrayCap.NormalArray);
GL.DisableClientState(ArrayCap.SecondaryColorArray);
GL.DisableClientState(ArrayCap.TextureCoordArray);
GL.DisableClientState(ArrayCap.VertexArray);

upon load to be absolutely sure.
Any help would be awesome!
Thanks!


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Craxic's picture
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
            GL.DrawElements(DrawType, indices.Length, DrawElementsType.UnsignedInt, indices);

I found the solution is that you have to unbind any buffer right before you draw if the final argument of DrawElements != IntPtr.Zero...

OpenGL: "Graphics cards are too powerful, let's make them annoyingly hard to use."
OpenGL: "Now with eight WHOLE error codes. GL_NO_ERROR, GL_YOU_FUCKED_UP, GL_YOU_FUCKED_UP_SOMEWHERE, GL_YOU_REALLY_FUCKED_UP, GL_YOU_REALLY_FUCKED_UP_SOMEWHERE, GL_TRAINWRECK_DETECTED, GL_HOTTER, GL_COLDER"