Sign in to follow this  
Thomo

CUSTOMVERTEX problem

Recommended Posts

My app currently can load in D3DxMeshes. The program works fine when I set my custom vertex to the following:

typedef struct
{
    D3DXVECTOR3      position;   // The 3D position for the vertex
   D3DXVECTOR3      normal;      // The 3D position for the

} CUSTOMVERTEX ;

#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL)


I copy the mesh, loaded in by the normal d3D way, into a mesh with my own vertex format. So I can pull out vertex details as I need them.
g_pMesh[iMeshCount]->CloneMeshFVF(D3DXMESH_SYSTEMMEM, D3DFVF_CUSTOMVERTEX, g_pd3dDevice[iMeshCount], &g_pMesh[iMeshCount]);

I then get a pointer to the vertex buffer, to give me acces to the values of each vertex (xyz, normals, uv).
g_pMesh[iMeshCount]->LockVertexBuffer(D3DLOCK_READONLY, (LPVOID*)&pVertexMesh[iMeshCount]);

g_pMesh[iMeshCount]->UnlockVertexBuffer();


Further in the code, I am copying the vertex values of the main mesh using the pointers provided by LockVertexBuffer:

for (DWORD index = 0; index <= iNumVerts-1; index++) {

pVertexMeshClone[index].x = pVertexMesh[0][index].x;
pVertexMeshClone[index].y = pVertexMesh[0][index].y;
pVertexMeshClone[index].z = pVertexMesh[0][index].z;

g_pMeshClone->LockVertexBuffer(D3DLOCK_DISCARD, (LPVOID*)&pVertexMeshClone);

g_pMeshClone->UnlockVertexBuffer();


The d3D meshclone was created earlier in the code. When i use the above CUSTOMVERTEX, the program works fine. I know this as I am printing the vertex of pVertexMesh (etc.) to the screen. However, when I declare my customvertex like this:

typedef struct
{
    D3DXVECTOR3      position;   // The 3D position for the vertex
    D3DXVECTOR3      normal;      // The 3D position for the vertex
    float           u, v;         // The texture coordinates
}

} CUSTOMVERTEX ;
// Our custom FVF, which describes our custom vertex structure
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX0)


the program crashes on pVertexMeshClone[index].x = pVertexMesh[0][index].x; I later relasied that I hadn't been allocating memory for the vertex buffer, so I added the following code:

iNumVerts = g_pMeshClone->GetNumVertices();
pVertexMeshClone = new CUSTOMVERTEX[iNumVerts];
ZeroMemory(&pVertexMeshClone, sizeof(CUSTOMVERTEX) * iNumVerts);


I do this in a similar way for the main mesh. Now when I run the program, it just exits when I try to load my mesh (from a menu). It doesn't even tell me if it's crashing.. Can someone help, please. Thanks

Share this post


Link to post
Share on other sites
Have you debugged the code and found out at what point it goes down?

I'm not certain about this but isn't a ZeroMemory call on a CUSTOMVERTEX risky since D3DXVECTOR3 contains other than value members in C++?

Share this post


Link to post
Share on other sites
D3DFVF_TEX0 should be D3DFVF_TEX1, since you're specifying 1 set of texture coordinates.

You should install the debug runtimes, they'll give you some useful information if a function fails, and they'll give you warnings about the vertex stride not matching the FVF you provided.

@staaf: D3DXVECTOR3 is just a structure containing 3 floats, and a bunch of overloaded operators, so ZeroMemory is safe on it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this