I was wondering if any of you had encountered one of these before (exception text is "Attempted to read or write protected memory. This is often an indication that other memory is corrupt"). I noticed in a search that this had been discussed previously, but I don't believe it's directly related to what I'm seeing.
Essentially, I'm trying to convert a ton of immediate mode calls over to use VBOs and I receive this exception on either a DrawArrays or DrawElements call. I've packed the buffering/drawing code purposefully close together to see if it helps (it doesn't). They typically reside in separate functions. Code follows:
uint VertexBufferIndex = 0; uint ElementBufferIndex = 0; uint TriIndices = new uint[this.tris.Length*3]; Vector3 verts = new Vector3[this.numVerts]; GL.GenBuffers(1, out this.VertexBufferIndex); GL.GenBuffers(1, out this.ElementBufferIndex);
GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.IndexArray); GL.BindBuffer(BufferTarget.ElementArrayBuffer, this.ElementBufferIndex); GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(this.TriIndices.Length * sizeof(uint)), this.TriIndices, BufferUsageHint.StaticDraw); GL.BindBuffer(BufferTarget.ArrayBuffer, this.VertexBufferIndex); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(this.verts.Length * 8 * sizeof(float)), this.verts, BufferUsageHint.StaticDraw); GL.DisableClientState(ArrayCap.VertexArray); GL.DisableClientState(ArrayCap.IndexArray); // DRAW VBO/IBO GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.IndexArray); //GL.DrawElements(BeginMode.Triangles, (int)this.numTris, DrawElementsType.UnsignedInt, 0); GL.DrawArrays(BeginMode.Triangles, 0, (int)this.numTris); GL.DisableClientState(ArrayCap.VertexArray); GL.DisableClientState(ArrayCap.IndexArray);
The error only crops up on the draw calls. If I comment both out, drawing and sim both continue on happily without error (albeit not displaying this object) and I can subsequently even read/write to/from the arrays that trigger the exception. GL.GetError returns no error.
Any ideas would be much appreciated. I can provide additional detail if required.
EDIT: fixed typo :)