I keep getting an access violation error while im trying to fill my terrain index buffer.
This problem has come out in many versions of my terrain engine and i fiddle with the code and it goes away but i havnt really changed anything.
So now im trying to figure out exactly what im doing wrong so i can stop it happening in future projects.
here is the structure of my terrain patch
struct sTerrainPatch
{
LPDIRECT3DTEXTURE8 PatchTexture;
LPDIRECT3DVERTEXBUFFER8 PatchVB;
LPDIRECT3DINDEXBUFFER8 PatchIB;
int NumVertices;
int NumIndices;
unsigned short *ind;
int x,y; //Position the the patch within the heightmap
bool inited;
bool filled;
};
and here is the source of the fill index buffer procedure
cTerrainEngine::FillPatchIndexBuffer(sTerrainPatch *patch)
{
HRESULT hr;
int i,j;
int currvert;
hr = patch->PatchIB->Lock( 0,
0,
(BYTE**)&patch->ind,
0);
if(FAILED(hr))
{
//write the error to the error log and then try and
//nicely quit the program
}
for(i=0;i<PATCHSIZE;i++)
for(j=0;j<PATCHSIZE;j++)
{
currvert = (j*PATCHSIZEVERTS)+i;
//Add the first tri of the tile
patch->ind[patch->NumIndices++] = currvert;
patch->ind[patch->NumIndices++] = currvert+1;
patch->ind[patch->NumIndices++] = currvert+PATCHSIZEVERTS+1;
//Add the second tri of the tile
patch->ind[patch->NumIndices++] = currvert;
patch->ind[patch->NumIndices++] = currvert+PATCHSIZEVERTS+1;
patch->ind[patch->NumIndices++] = currvert+PATCHSIZEVERTS;
}
patch->PatchIB->Unlock();
}
if you need anything else i''ll post it up asap