# VertexBuffer Access

## Recommended Posts

When I have compiled my project I get an error about Access Violation Error. I do not know the cause of this, but I think it is because of the vertexbuffer. I have a code like that.What I want to do is,just to create boundry objects of my models.
 vertexBufferBD[range] = new VertexBuffer(mesh.SourceMesh.VertexFormat.GetType(),
boundryVertices.Length, modelDevice,
Usage.WriteOnly,
mesh.SourceMesh.VertexFormat,
Pool.Default);
vertexBufferBD[range].SetData(boundryVertices, 0, LockFlags.None);
vertexBufferBD[range].Unlock();

GraphicsStream graphicsBuffer = vertexBufferBD[range].Lock(0, 0, LockFlags.None);
radius = Geometry.ComputeBoundingSphere(graphicsBuffer, vCount, mesh.SourceMesh.VertexFormat, out objectCenter);


So,does anyone help to solve my problem?I will be very happy,if so.

##### Share on other sites
Evil Steve    2017
At a guess, I'd say that it's because you create your vertex buffer as write only, but then read from it. Aside from that, are you sure the lock succeeds? I don't know how you test this in MDX...

##### Share on other sites
sirob    1181
Quote:
 Original post by Evil SteveAt a guess, I'd say that it's because you create your vertex buffer as write only, but then read from it. Aside from that, are you sure the lock succeeds? I don't know how you test this in MDX...

Sounds right. In MDX, if a call fails, it would throw an exception, so at least the problem of calls "silently" failing doesn't exist :).