Direct X の C++ で Load Mesh 関数を作成する際に問題が発生しました。「_.exe の 0x00401e64 で未処理の例外: 0xC00000005: アクセス違反の読み取り位置 0x83e05597」というエラーが発生するようです。私はそれがこの行でクラッシュしていることを知っています:
D3DXMATERIAL* tempMaterials = (D3DXMATERIAL*)bufMaterial->GetBufferPointer();
関数全体は次のようになります (直接の X ヘルプについては、これまで directxtutorial.com をたどっています)。
void LoadModel(Model* model, LPCTSTR File){
LPD3DXBUFFER bufMaterial;
D3DXLoadMeshFromX(File, D3DXMESH_SYSTEMMEM, d3ddev, NULL, &bufMaterial, NULL,
&model->numMaterials, &model->Mesh);
OutputDebugString("LOAD MESH \n");
D3DXMATERIAL* tempMaterials = (D3DXMATERIAL*)bufMaterial->GetBufferPointer();
OutputDebugString("GET BUFFER\n");
model->Material = new D3DMATERIAL9[model->numMaterials];
model->Texture = new LPDIRECT3DTEXTURE9[model->numMaterials];
OutputDebugString("LOAD MESH \n");
for(DWORD index = 0; index < model->numMaterials; index++)
{
model->Material[index] = tempMaterials[index].MatD3D;
model->Material[index].Ambient = model->Material[index].Diffuse;
// if there is a texture to load, load it
if(FAILED(D3DXCreateTextureFromFileA(d3ddev,
tempMaterials[index].pTextureFilename,
&model->Texture[index])))
model->Texture[index] = NULL; // if there is no texture, set the texture to NULL
}
return;}
私はそれを次のように呼びます:
LoadModel(networkBase, TEXT("E:\\C++\\Skirmish\\X\\gridbox.x"));
しかし、クラッシュしている行のように、一時的なマテリアル バッファからのマテリアル バッファのこのタイプのキャストをすべて使用する古い Beginning DirectX ブックと別の Web サイト ソースを見つけました。助けてください!