Sign in to follow this  

Grid Creation Problem

This topic is 2486 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
[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[i].mPos = Vertices[i].mPos;
vertex[i].mNormal = Vertices[i].mNormal;
vertex[i].mTex = Vertices[i].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));
[/code]

the errors start when i invoke the D3DXComputeNormals() function
here they are
[code]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).
[/code]

really appreciate the help guys

Share this post


Link to post
Share on other sites
[quote name='Buckeye' timestamp='1298485428' post='4778054']
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 ]?
[/quote]

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??

Share this post


Link to post
Share on other sites

This topic is 2486 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this