hannesh's picture


I have been really careful to store everything server side, but I still get these very rare AccessViolationExceptions when I call DrawArrays (it can take minutes before it happens).

I'm using vertex array objects;

            GL.GenVertexArrays(1, out VAOid);
            GL.GenBuffers(1, out VBOid);
            GL.BindBuffer(BufferTarget.ArrayBuffer, VBOid);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(n * myVertex.SizeInBytes), vertices, BufferUsageHint.DynamicDraw);
            vertices = null;

And to draw:

             GL.DrawArrays(BeginMode.Quads, 0, VertexTypeOffsets[VertexTypeOffsets.Length - 2]);

Is it alright to set my client side vertex array to null and let the garbage collecter clean it up straight after GL.BufferData?
What else can cause AccessViolationExceptions?


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

The client-side vertex array isn't touched again once GL.BufferData returns.

AccessViolationExceptions typically indicate out-of-bounds accesses. Make sure your 'count' parameters are within bounds (e.g. in GL.DrawArrays) and that you disable any vertex attributes (vertex pointers) you are not using whenever you bind a different vertex array. If you use GL.DrawElements, make sure that all offsets are within bounds.

OpenTK can catch a number of bugs if you run it in debug mode (open OpenTK.sln, compile in "Debug" configuration and copy the resulting OpenTK.dll to your project).