嗨我最近與DirectX9合作,我遇到了這個錯誤。儘管它與DirectX無關。這是我的。與陣列運行時錯誤
struct D3DVertex
{
float x, y, z;
DWORD Color;
};
int main()
{
D3DVertex *TestShape = new D3DVertex();
TestShape[0].x = 0.0f;
TestShape[0].y = 2.0f;
TestShape[0].z = 0.5f;
TestShape[0].Color = 0xffffffff;
TestShape[1].x = -2.0f;
TestShape[1].y = -2.0f;
TestShape[1].z = 0.5f;
TestShape[1].Color = 0xffffffff;
TestShape[2].x = 2.0f;
TestShape[2].y = -2.0f;
TestShape[2].z = 0.5f;
TestShape[2].Color = 0xffffffff;
return 0;
}
當我運行它時,它給我一個運行時錯誤,說這個。
Windows has triggered a breakpoint in x.exe.
This may be due to a corruption of the heap, which indicates a bug in x.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while x.exe has focus.
The output window may have more diagnostic information.
但是當我走這條線走TestShape[2].z = 0.5f;
錯誤消失。 爲什麼會發生這種情況,我該如何解決這個問題。請幫忙。
您創建了一個對象並像數組一樣訪問。那是問題所在。使用它來創建對象的數組(大小3)D3DVertex * TestShape = new D3DVertex [3]; – 999k 2013-03-10 12:41:11
我該如何解決這個問題? – Efex 2013-03-10 12:41:42