Skip to main content
GameDev.net gamedev.net
🔒 Locked

wired Access violation!!

Started by pranaykamat Nov 27, 2004 at 8:55 PM 1 replies 800+ views
Original Post
pranaykamat
pranaykamat
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


Alex Swinney
Alex Swinney
indexbuffers hold an array of shorts, won't solve your problem, but it might help.

I WISH SOMEONE WOULD FIX THE DAMNED LOGIN!
pranaykamat
pranaykamat
hi, thanks for that info.. but it dint help :-( did more debugin toady found that..

the code below works !!! note that am still using "idx+=6" so its still takin the same amount of memory..

[source c++]int idx=0;DWORD vIndex=0;for(i=0;i<height-1;i++) for(int j=0;j<width-1;j++) {   // fill in the face index data   vIndex = (i*width)+j;   vStruct[idx]   = 0;//(DWORD)vIndex;    vStruct[idx+1] = 0;//(DWORD)vIndex+1;    //vStruct[idx+2] = 0;//(DWORD)(vIndex*STEP_SIZE)+1;   //vStruct[idx+3] = 0;//(DWORD)vIndex;    //vStruct[idx+4] = 0;//(DWORD)(vIndex*STEP_SIZE)+1;    //vStruct[idx+5] = 0;//(DWORD)vIndex*STEP_SIZE;   //vStruct[idx]=j;   idx+=6; }


Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.