Original Post
hi guys, Am trying to optimise my the mesh vertices. the problem is i get a access violation when i try to get the vertex buffer after setting the index buffer! Am very sure of the values am setting for the vertex and index buffer and dont think its got anythign to do with that. the wierd thing is if i comment the block of code which sets the index buffer its works perfectly fine!! i think its corupting my vertex buffer becuse the second call to GetVertexBuffer gives access violation.
ID3DXMesh* pMesh = 0;
hr = D3DXCreateMeshFVF(
961, // numFaces
MAP_SIZE,
D3DXMESH_MANAGED,
Vertex::FVF,
Device,
&pMesh);
int boxNo=0;
int ii=0;
int i=0;
Vertex* v = 0;
pMesh->LockVertexBuffer(0, (void**)&v);
for(i=0;i<height-1;i++){
for(int j=0;j<width-1;j++){
ii = (i*width)+j;
v[boxNo] = pVertex[ii];
v[boxNo+1] = pVertex[ii+1];
v[boxNo+2] = pVertex[(ii+1)*width];
v[boxNo+3] = pVertex[ii*width];
boxNo += 4;
}
}
pMesh->UnlockVertexBuffer();
pMesh->GetVertexBuffer(&pVB); // Debuging
int* vStruct = 0;
pMesh->LockIndexBuffer(D3DLOCK_DISCARD, (void**)&vStruct);
int idx=0;
int vIndex=0;
for(i=0;i<height-1;i++) {
for(int j=0;j<width-1;j++)
{
vIndex = (i*width)+j;
vStruct[idx] = vIndex;
vStruct[idx+1] = vIndex+1;
vStruct[idx+2] = (vIndex*STEP_SIZE)+1;
vStruct[idx+3] = vIndex;
vStruct[idx+4] = (vIndex*width)+1;
vStruct[idx+5] = vIndex*width;
idx+=6;
}
}
pMesh->UnlockIndexBuffer()
pMesh->GetVertexBuffer(&pVB); // Debuging