Jump to content
  • Advertisement
Sign in to follow this  

My loading Multiple mesh function is crashing

This topic is 2162 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to create mesh functional that can load meshs easy with just calling the same functions over and over,this seems to be crashing and i dont know why :(


Struct and Array

struct Mesh
std::vector<IDirect3DTexture9*> m_textures;
std::vector<Mtrl> mMtrl;
D3DMATERIAL9 m_white;
Mesh meshs[2];


void LoadXFile(
const std::string& filename, 
LPD3DXMESH &m_pMesh,
std::vector<Mtrl>& mtrls, 
std::vector<IDirect3DTexture9*>& texs)
// Step 1: Load the .x file from file into a system memory mesh.
ID3DXMesh* meshSys = 0;
ID3DXBuffer* adjBuffer = 0;
ID3DXBuffer* mtrlBuffer = 0;
DWORD numMtrls = 0;
D3DXLoadMeshFromX(filename.c_str(), D3DXMESH_SYSTEMMEM, pd3dDevice,
&adjBuffer, &mtrlBuffer, 0, &numMtrls, &m_pMesh);
if(m_pMesh != NULL)
// MessageBox(NULL,"Mesh[0] OK","",0);
if( mtrlBuffer != 0 && numMtrls != 0 )
D3DXMATERIAL* d3dxmtrls = (D3DXMATERIAL*)mtrlBuffer->GetBufferPointer();
for(DWORD i = 0; i < numMtrls; ++i)
// Save the ith material. Note that the MatD3D property does not have an ambient
// value set when its loaded, so just set it to the diffuse value.
Mtrl m;
m.ambient = d3dxmtrls[i].MatD3D.Diffuse;
m.diffuse = d3dxmtrls[i].MatD3D.Diffuse;
m.spec = d3dxmtrls[i].MatD3D.Specular;
m.specPower = d3dxmtrls[i].MatD3D.Power;
mtrls.push_back( m );
// Check if the ith material has an associative texture
if( d3dxmtrls[i].pTextureFilename != 0 )
// Yes, load the texture for the ith subset
IDirect3DTexture9* tex = 0;
char* texFN = d3dxmtrls[i].pTextureFilename;
D3DXCreateTextureFromFile(pd3dDevice, texFN, &tex);
// Save the loaded texture
texs.push_back( tex );
// No texture for the ith subset
texs.push_back( 0 );
//ReleaseCOM(mtrlBuffer); // done w/ buffer


void RenderMesh(LPD3DXMESH m_pMesh,D3DXMATRIX World,std::vector<IDirect3DTexture9*> mTex,std::vector<Mtrl> mMtrl)
pd3dDevice->SetTransform( D3DTS_WORLD, &World );
for(int j = 0; j < mMtrl.size(); ++j)
if(mTex[j] != 0)
pd3dDevice->SetTexture(0, mTex[j]);


Edited by Anddos

Share this post

Link to post
Share on other sites

Can you be more specific about what is crashing?  What error message do you get?  It will be very difficult to help if you don't give any information about what you are seeing...

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!