Issues with Locking VertexBuffers (MDX C#)

Started by
-1 comments, last by CubeReturns 20 years ago
I''ve spent all day trying to get skeletal animation working, but to no avail. I''ve found 7 documents and all have a different approach, and most are in languages I don''t understand. I found one here on GameDev, and that''s the one I''m following. Though it''s in C++, I''ve managed to translate it to C#. But I''m stuck on this one step: C++:

				// Lock the meshes'' vertex buffers

				void *SrcPtr, *DestPtr;
				pMesh->MeshData.pMesh->LockVertexBuffer(D3DLOCK_READONLY, (void**)&SrcPtr);
				pMesh->pSkinMesh->LockVertexBuffer(0, (void**)&DestPtr);

				// Update the skinned mesh using provided transformations

				pMesh->pSkinInfo->UpdateSkinnedMesh(m_pBoneMatrices, NULL, SrcPtr, DestPtr);

				// Unlock the meshes vertex buffers

				pMesh->pSkinMesh->UnlockVertexBuffer();
				pMesh->MeshData.pMesh->UnlockVertexBuffer();
Seems simple enough, right? There are multiple ways to get the vertexbuffers locked in C#. You can use Mesh.LockVertexBuffer, or Mesh.VertexBuffer.Lock, and both of those have overloads. Some overloads return a GraphicsStream object, which I have no use for, I need an array to pass to the UpdateSkinnedMesh function.

					Mesh SrcMesh = cm.MeshData.Mesh;
					Mesh DestMesh = cm.SkinnedMesh;
					D3D.CustomVertex.PositionTextured[] Src = new D3D.CustomVertex.PositionTextured[200];
					Src = (D3D.CustomVertex.PositionTextured[]) SrcMesh.VertexBuffer.Lock(0,LockFlags.ReadOnly);

					Array Dest = DestMesh.LockVertexBuffer(DestMesh.VertexFormat.GetType(),LockFlags.None,new int[]{DestMesh.NumberVertices});

					cm.SkinInformation.UpdateSkinnedMesh(BoneMatrices,null,Src,out Dest) ;

					cm.SkinnedMesh.UnlockVertexBuffer();
					cm.MeshData.Mesh.UnlockVertexBuffer();

This is currently my code, though I''ve changed over and over which method and overload to use and all. Basically I get one of two errors : Object contains non-Primitive or non-Blittable data, or Value cannot be null. I''m starting to think there''s just a bug in MDX or something, because I just can''t find what the problem is. It appears on the first Lock, by the way. Any ideas? Thanks in advance

This topic is closed to new replies.

Advertisement