Jump to content
  • Advertisement
Sign in to follow this  
ta0soft

DataStream.Write question

This topic is 2340 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

I'm trying to convert my C++/D3D9 code to C#/SlimDX but I keep getting the error "Attempted to read past the end of the stream" when I build the mesh. Am I writing to the DataStream incorrectly?

[source]
// C++
if (FAILED(D3DXCreateMeshFVF((DWORD)meshVertices.size() / 3, (DWORD)meshVertices.size(), D3DXMESH_MANAGED, FVF_MESHVERTEX, p_Device, &p_Mesh))) return false;

void* vertices;
if (FAILED(p_Mesh->LockVertexBuffer(D3DLOCK_NOSYSLOCK, (void**)&vertices))) return false;
memcpy(vertices, &(meshVertices[0]), meshVertices.size() * sizeof(MeshVertex));
if (FAILED(p_Mesh->UnlockVertexBuffer())) return false;
// Fill the index buffer

void* indices;
if (FAILED(p_Mesh->LockIndexBuffer(D3DLOCK_NOSYSLOCK, (void**)&indices))) return false;
memcpy(indices, &(meshIndices[0]), meshIndices.size() * sizeof(WORD));
if (FAILED(p_Mesh->UnlockIndexBuffer())) return false;

DWORD* attributes;
if (FAILED(p_Mesh->LockAttributeBuffer(D3DLOCK_NOSYSLOCK, (DWORD**)&attributes))) return false;
memcpy(attributes, &(meshAttributes[0]), meshAttributes.size() * sizeof(DWORD));
if (FAILED(p_Mesh->UnlockAttributeBuffer())) return false;
[/source]

[source]
// C#
p_Mesh = new Mesh(p_Direct3D9.Device, meshVertices.Count / 3, meshVertices.Count, MeshFlags.Managed, MeshVertex.Format);

DataStream dataStream = p_Mesh.LockVertexBuffer(LockFlags.NoSystemLock);
dataStream.WriteRange<MeshVertex>(meshVertices.ToArray());
if (p_Mesh.UnlockVertexBuffer().IsFailure) return false;

dataStream = p_Mesh.LockIndexBuffer(LockFlags.NoSystemLock);
dataStream.WriteRange(meshIndices.ToArray());
if (p_Mesh.UnlockIndexBuffer().IsFailure) return false;

dataStream = p_Mesh.LockAttributeBuffer(LockFlags.NoSystemLock);
dataStream.WriteRange(meshAttributes.ToArray());
if (p_Mesh.UnlockAttributeBuffer().IsFailure) return false;
[/source]

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!