loading mulitple Mesh.x files at once

Started by
0 comments, last by Gage64 13 years, 6 months ago
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,    // load this file                      D3DXMESH_SYSTEMMEM,    // load the mesh into system memory                      d3ddev,    // the Direct3D Device                      NULL,    // we aren't using adjacency                      &bufShipMaterial2,    // put the materials here                      NULL,    // we aren't using effect instances                      &numMaterials2,    // the number of materials in this model                      &meshs);    // put the mesh here , its crashing here   if(SUCCEEDED(hr))   {	   MessageBox(NULL,mesharray,"loaded",0);   }   else   {	   //MessageBox(NULL,"gun model not loaded","",0);   }	}}


in the class .h i have

//multiple mesh dataLPD3DXMESH meshs[2];    // define the mesh pointerLPD3DXBUFFER bufShipMaterial2[2];D3DMATERIAL9* material2[2];    // define the material objectLPDIRECT3DTEXTURE9* texture2[2];    // a pointer to a textureDWORD numMaterials2[2];    // stores the number
:)
Advertisement
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]);

This topic is closed to new replies.

Advertisement