Advertisement Jump to content
Sign in to follow this  

MDX VertexBuffer locking problem

This topic is 4904 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

help me out here please. I am doing a tutorial with MDX August 2005 refresh. I am using Visual C# Express Beta 2 for my coding. In the tutorial they have me creating an array of vertices. The ide is complaining at run time not compile time when it hits this line. what is going on.
CustomVertex.PositionNormal[] verts = (CustomVertex.PositionNormal[]) vertices.Lock(0,0);

Share this post

Link to post
Share on other sites
Here are the methods that handle the vertexbuffer

protected VertexBuffer CreateVertexBuffer(Device device)
VertexBuffer buf = new VertexBuffer(typeof(CustomVertex.TransformedTextured),


return buf;

protected void PopulateVertexBuffer(VertexBuffer vertices)
CustomVertex.PositionNormal[] verts =
(CustomVertex.PositionNormal[]) vertices.Lock(0,0);

for (int i = 0; i < 50; i++)
float theta = (float)(2 * Math.PI * i) / 49;
verts[2 * i].Position = new Vector3((float)Math.Sin(theta), -1, (float)Math.Cos(theta));
verts[2 * i].Normal = new Vector3((float)Math.Sin(theta), 0, (float)Math.Cos(theta));
verts[2*i+1].Position = new Vector3((float)Math.Sin(theta), 1, (float)Math.Cos(theta));
verts[2*i+1].Normal = new Vector3((float)Math.Sin(theta), 0, (float)Math.Cos(theta));


here is the render method which calls the setting up of the vertex buffer

protected void Render()
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0F, 0);


// render here

device.VertexFormat = CustomVertex.PositionNormal.Format;
device.SetStreamSource(0, vertices, 0);
device.DrawPrimitives(PrimitiveType.TriangleList, 0, 98);



Share this post

Link to post
Share on other sites
You're creating a vertex buffer to hold CustomVertex.TransformedTextured vertices, and then you try to fill it with CustomVertex.PositionNormal ones. Change TransformedTextured to PositionNormal.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!