Sign in to follow this  
Anddos

loading mulitple Mesh.x files at once

Recommended Posts

I am getting a crash problem with this code


void MeshX::LoadMultipleMeshs(LPDIRECT3DDEVICE9 d3ddev)
{
char *mesharray[] = {"models/mp5.x","models/mp5.x"};

for(int i = 0; i < sizeof(mesharray); i++)
{
hr = D3DXLoadMeshFromX(mesharray[i], // load this file
D3DXMESH_SYSTEMMEM, // load the mesh into system memory
d3ddev, // the Direct3D Device
NULL, // we aren't using adjacency
&bufShipMaterial2[i], // put the materials here
NULL, // we aren't using effect instances
&numMaterials2[i], // the number of materials in this model
&meshs[i]); // put the mesh here , its crashing here

if(SUCCEEDED(hr))
{
MessageBox(NULL,mesharray[i],"loaded",0);
}
else
{
//MessageBox(NULL,"gun model not loaded","",0);
}

}
}


in the class .h i have


//multiple mesh data
LPD3DXMESH meshs[2]; // define the mesh pointer
LPD3DXBUFFER bufShipMaterial2[2];
D3DMATERIAL9* material2[2]; // define the material object
LPDIRECT3DTEXTURE9* texture2[2]; // a pointer to a texture
DWORD numMaterials2[2]; // stores the number

Share this post


Link to post
Share on other sites
sizeof(mesharray) is not the number of elements in the array. It's the size of the whole array in bytes. In this case it's probably 8 - the size of two char pointers.

To get the number of elements you can do this:

int size = sizeof(mesharray) / sizeof(mesharray[0]);

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