hey.....i am making a game in which there will be some cubes...meshes.....i am importing the cubes in DX thru .x files...but whenever i import meshes with parameter ID3DXMesh* ...the program crashes...here is the code....
//--------------CODE-----------------------------------------
bool CGameCore::LoadWorld(LPCWSTR xFilename, ID3DXMesh* meshName){
D3DXCreateBuffer(sizeof(int) * 4, &matBuffer);
if(FAILED(D3DXLoadMeshFromXW(xFilename, D3DXMESH_MANAGED, pD3DObj->d3ddev,
&adjBuffer, &matBuffer, NULL, &numMat, &meshName)))
return FALSE;
if(matBuffer != 0 && numMat != 0){
D3DXMATERIAL* matInfo = (D3DXMATERIAL*)matBuffer->GetBufferPointer();
for(DWORD i = 0; i < numMat; i++){
matInfo.MatD3D.Ambient = matInfo.MatD3D.Diffuse;
mat.push_back(matInfo.MatD3D);
if(matInfo.pTextureFilename != 0){
IDirect3DTexture9* texInfo = 0;
if(FAILED(D3DXCreateTextureFromFileW(pD3DObj->d3ddev,(LPCWSTR)matInfo.pTextureFilename,
(LPDIRECT3DTEXTURE9*)&texInfo)))
return FALSE;
tex.push_back(texInfo);
}
else tex.push_back(0);
}
}
if(matBuffer){
matBuffer->Release();
matBuffer = NULL;
}
return TRUE;
}
//------------------------------CODE------------------------------------
void CGameCore::DrawMesh(float xx, float yy, float zz, ID3DXMesh* meshName){
static float x = 0.0f; //strafe
static float y = 0.0f; //fly
static float z = 0.0f; //walk
if(KEY('W')) y += 0.5f;
if(KEY('S')) y -= 0.5f;
if(KEY('A')) x -= 0.5f;
if(KEY('D')) x += 0.5f;
D3DXMATRIX rotateMesh;
D3DXMATRIX transMesh;
D3DXMatrixRotationY(&rotateMesh, D3DXToRadian(-90));
D3DXMatrixTranslation(&transMesh, x + xx, y + yy, z + zz);
pD3DObj->d3ddev->SetTransform(D3DTS_WORLD, &(rotateMesh * transMesh));
for(DWORD i = 0; i < mat.size(); i++){
pD3DObj->d3ddev->SetMaterial(&mat);
pD3DObj->d3ddev->SetTexture(0, tex);
meshName->DrawSubset(i);
}
}
//*************************************************************
Now when i call the these two function in the renderScene() --
//----------------------------CODE----------------------------
void CGameCore::RenderScene(){
pD3DObj->ClearBackBuffer();
pD3DObj->Begin();
pD3DObj->RenderD3D9();
LoadWorld(L"xHeli.x", mHeli); //where mHeli & mWorld are the meshes for helicopter & cube
DrawMesh(0, 0, 10); // -- which i want to load in my game
LoadWorld(L"xWorld.x");
DrawMesh(0, 0, 5,mWorld);
pD3DObj->End();
}
//---------------------CODE----------------------------
the program crashes...
I debugged it and found that the ID3DXMesh* meshName has NULL value...another thing is if i'm importing these two mesh without the ID3DXMesh* parameter in the LoadMesh() and DrawMesh() function...the mesh are loaded but the cube's (xWorld.x file) color, which has grey color, becomes red, which is actually helicopter's (xHeli.x) color....
so can anyone tell how solve this prob.....
Thanx.
[Edited by - The Nameless on April 17, 2009 5:33:35 PM]