Jump to content

  • Log In with Google      Sign In   
  • Create Account


DataStream.Write question


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 ta0soft   Members   -  Reputation: 123

Like
0Likes
Like

Posted 21 February 2012 - 03:41 AM

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?


// 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;




// 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;



Sponsor:

#2 ta0soft   Members   -  Reputation: 123

Like
0Likes
Like

Posted 21 February 2012 - 05:03 AM

Nevermind I figured it out, I was using int to store indices and SlimDX was expecting short :D




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS