
AccessViolationException
Posted Friday, 4 February, 2011 - 17:30 by hannesh inI 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.BindVertexArray(VAOid); GL.BindBuffer(BufferTarget.ArrayBuffer, VBOid); SetVertexPointers(); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(n * myVertex.SizeInBytes), vertices, BufferUsageHint.DynamicDraw); GL.BindVertexArray(0); vertices = null;
And to draw:
GL.BindVertexArray(VAOid); GL.DrawArrays(BeginMode.Quads, 0, VertexTypeOffsets[VertexTypeOffsets.Length - 2]); GL.BindVertexArray(0);
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?


Comments
Re: AccessViolationException
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).