Grid Creation Problem

Started by
3 comments, last by VISQI 13 years, 1 month ago
Hey guys,
I am having trouble with my terrain creation code
When i try to construct a grid, these weird errors start to flood the debug output.
here is the grid creation code

std::vector<Vertex> Vertices;
std::vector<DWORD> Indices;

CreateGrid(mTerr->GetVertCols(), mTerr->GetVertRows(), mTerr->Getdx(), mTerr->Getdz()
, D3DXVECTOR3(0.0f, 0.0f, 0.0f), mTerr->mMap, Vertices, Indices);

DWORD TotalVert = (mTerr->GetVertCols()) * (mTerr->GetVertRows());
DWORD TotalPoly = (mTerr->GetVertCols() - 1) * (mTerr->GetVertRows() - 1) * 2;

ID3DXMesh* Grid = 0;
D3DVERTEXELEMENT9 elements[65];
UINT NumElements = 0;
Vertex::Decl->GetDeclaration(elements, &NumElements);
BHR(D3DXCreateMesh(TotalPoly, TotalVert, D3DXMESH_MANAGED|D3DXMESH_32BIT,
elements, gd3dDev, &Grid));

Vertex* vertex = 0;
if(SUCCEEDED(Grid->LockVertexBuffer(0, (void**)&vertex)))
{
for(DWORD i = 0; i < Grid->GetNumVertices(); ++i)
{

vertex.mPos = Vertices.mPos;
vertex.mNormal = Vertices.mNormal;
vertex.mTex = Vertices.mTex;
}
BHR(Grid->UnlockVertexBuffer());

}

WORD* index = 0;
if(SUCCEEDED(Grid->LockIndexBuffer(0, (void**)&index)))
{
for(DWORD i = 0; i < Grid->GetNumFaces(); ++i)
{
index[i + 0] = Indices[i + 0];
index[i + 1] = Indices[i + 1];
index[i + 2] = Indices[i + 2];
}
BHR(Grid->UnlockIndexBuffer());
}

BHR(D3DXComputeNormals(Grid, 0));


the errors start when i invoke the D3DXComputeNormals() function
here they are
D3DX: D3DXValidIndices: A point(0) was found more than once in triangle 1
.
.
.
.
D3DX: D3DXValidIndices: A point(0) was found more than once in triangle 131070
D3DX: D3DXValidIndices: A point(0) was found more than once in triangle 131071
The thread 'Win32 Thread' (0x100c) has exited with code 0 (0x0).
D3DX: D3DXComputeTangentFrame: Mesh is not valid
First-chance exception at 0x51ca370b in TerrainGridDemo.exe: 0xC0000005: Access violation reading location 0x25c50060.
Unhandled exception at 0x51ca370b in TerrainGridDemo.exe: 0xC0000005: Access violation reading location 0x25c50060.
The program '[5236] TerrainGridDemo.exe: Native' has exited with code -1073741819 (0xc0000005).


really appreciate the help guys
Advertisement
The way you load the indices is suspect. You run the variable i from 0 to numFaces, loading indices from 0 to numFaces+2. Instead of index[i+0], do you mean to use index[ i*3 + 0 ]?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.


The way you load the indices is suspect. You run the variable i from 0 to numFaces, loading indices from 0 to numFaces+2. Instead of index[i+0], do you mean to use index[ i*3 + 0 ]?


i overlooked that one. I corrected it, but the same problem is still there.
i think it is because WORD's limit is 65532 and GetNumFaces() * 3 = 393216.
i don't think that i can use DWORD for indices.
what data type can i use??
Create the mesh with 32 bit indices. See D3DXMESH options. Then use DWORD.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Everything went good, thx for the help, buckeye.

This topic is closed to new replies.

Advertisement