Skip to main content
GameDev.net gamedev.net
🔒 Locked

CUSTOMVERTEX problem

Started by Thomo May 20, 2006 at 5:59 AM 1 replies 550+ views
Original Post
Thomo
Thomo
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
Staffan E
Staffan E
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++?
Hack my projects! Oh Yeah! Use an SVN client to check them out.BlockStacker
Evil Steve
Evil Steve
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.