Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#Actualta0soft

Posted 21 February 2012 - 05:02 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;


#6ta0soft

Posted 21 February 2012 - 04:59 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;



Edit: it appears that the error is occuring when I write to the index buffer stream, should I be using int or long?

#5ta0soft

Posted 21 February 2012 - 04:57 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;


#4ta0soft

Posted 21 February 2012 - 04:47 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<int>(meshIndices.ToArray());

if (p_Mesh.UnlockIndexBuffer().IsFailure) return false;



dataStream = p_Mesh.LockAttributeBuffer(LockFlags.NoSystemLock);

dataStream.WriteRange<int>(meshAttributes.ToArray());

if (p_Mesh.UnlockAttributeBuffer().IsFailure) return false;


#3ta0soft

Posted 21 February 2012 - 04:46 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<int>(indices.ToArray());

if (p_Mesh.UnlockIndexBuffer().IsFailure) return false;



dataStream = p_Mesh.LockAttributeBuffer(LockFlags.NoSystemLock);

dataStream.WriteRange<int>(attributes.ToArray());

if (p_Mesh.UnlockAttributeBuffer().IsFailure) return false;


#2ta0soft

Posted 21 February 2012 - 03:43 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);

foreach (MeshVertex meshVertex in meshVertices)

{

//dataStream.Write(meshVertex);

dataStream.Write(meshVertex.Position);

dataStream.Write(meshVertex.Normal);

dataStream.Write(meshVertex.UV);

}

if (p_Mesh.UnlockVertexBuffer().IsFailure) return false;



dataStream = p_Mesh.LockIndexBuffer(LockFlags.NoSystemLock);

foreach (int index in meshIndices)

{

dataStream.Write(index);

}

if (p_Mesh.UnlockIndexBuffer().IsFailure) return false;



dataStream = p_Mesh.LockAttributeBuffer(LockFlags.NoSystemLock);

foreach (int attribute in meshAttributes)

{

dataStream.Write(attribute);

}

if (p_Mesh.UnlockAttributeBuffer().IsFailure) return false;


PARTNERS