我在 C++ 中为 Direct X 创建加载网格函数时遇到问题。我似乎收到此错误:“_.exe 中 0x00401e64 处的未处理异常:0xC00000005:访问冲突读取位置 0x83e05597”。我知道它在这条线上崩溃了:
D3DXMATERIAL* tempMaterials = (D3DXMATERIAL*)bufMaterial->GetBufferPointer();
整个函数看起来像这样(到目前为止,我一直在关注 directxtutorial.com 以获得直接的 X 帮助)。
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 书和另一个网站源,它们都使用这种从临时材质缓冲区转换材质缓冲区的类型,就像正在崩溃的行所做的那样。请帮忙!