我正在使用 DirectX9 通过手动组装地面的顶点来处理一些简单的地形。
在我设置索引的代码部分,我得到了一个错误:
Windows 在 test.exe 中触发了一个断点。
这可能是由于堆损坏,这表明 test.exe 或其已加载的任何 DLL 中存在错误。
这是我的代码中给我带来问题的部分,我几乎 100% 确定它已链接到我的索引指针,但我完成后将其删除......所以我不确定是什么问题是。
int total = widthQuads * heightQuads * 6;
DWORD *indices = new DWORD[totalIdx];
for (int y = 0; y < heightQuads; y++)
{
for (int x = 0; x < widthQuads; x++)
{ //Width of nine:
int lowerLeft = x + y * 9;
int lowerRight = (x + 1) + y * 9;
int topLeft = x + (y + 1) * 9;
int topRight = (x + 1) + (y + 1) * 9;
//First triangle:
indices[counter++] = topLeft;
indices[counter++] = lowerRight;
indices[counter++] = lowerLeft;
//Second triangle:
indices[counter++] = topLeft;
indices[counter++] = topRight;
indices[counter++] = lowerRight;
}
}
d3dDevice->CreateIndexBuffer(sizeof(DWORD)* total, 0, D3DFMT_INDEX16,
D3DPOOL_MANAGED, &groundindex, 0);
void* mem = 0;
groundindex->Lock(0, 0, &mem, 0);
memcpy(mem, indices, total * sizeof (DWORD));
groundindex->Unlock();
delete[] indices;
当我删除此块时,我的程序运行正常。