Archived

This topic is now archived and is closed to further replies.

Trouble copying vertices...

This topic is 5235 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

I am trying to create an indexed VB so that I can do culling by just redoing the indices. However I can''t seem to get the VB to copy. I''m not sure what the problem is quite... I have a little member function that looks like this:
void Heightmap::CreateVB()
{
	void *pData;
	HMVERTEX *Vertices = NULL;
	Vertices = new HMVERTEX[dividedheight*dividedwidth];
	
	int x = 0;
	int y = 0;
	for (y = 0;y<dividedheight;y++)
		for (x = 0;x<dividedwidth;x++)
		{

			Vertices[y*dividedheight+x].x = (MapX-(MapWidth/2)) + ((MapWidth/dividedwidth)*x);
			Vertices[y*dividedheight+x].z = (MapZ-(MapDepth/2)) + ((MapDepth/dividedheight)*y);
			Vertices[y*dividedheight+x].y = MapY + realmap[x][y];


			if(x ==0) Vertices[y*dividedheight+x].u1 = 0;
			else
			{

				Vertices[y*dividedheight+x].u1 = dividedwidth / (float)x;
				Vertices[y*dividedheight+x].u2 = (float)(x%2);
			}
			if (y == 0) Vertices[y*dividedheight+x].u1 = 0;
			else 
			{
				Vertices[y*dividedheight+x].v1 = dividedheight / (float)y;
				Vertices[y*dividedheight+x].v2 = (float)(y%2);
			}
		}
		OutputDebugString("Creating Vertex Buffer...\n");
 		mp_d3ddevice->CreateVertexBuffer(sizeof(Vertices),D3DUSAGE_WRITEONLY,D3DFVF_HMVERTEX,D3DPOOL_MANAGED,&pHMVB,NULL);
		OutputDebugString("Created Vertex Buffer...\n");
		OutputDebugString("Locking Memory...\n");
		pHMVB->Lock(0,sizeof(pData),(void**)&pData,0);
		OutputDebugString("Locked Memory...\n");

		OutputDebugString("Copying Memory...\n");

		memcpy(pData,Vertices,sizeof(Vertices));
		OutputDebugString("Copied Memory...\n");
		OutputDebugString("UnLocking Memory...\n");

		pHMVB->Unlock();
		OutputDebugString("Unlocked Memory...\n");

}
Well, it crashes on ''Locking Memory''. The last few lines of my Debug Window...
Creating Vertex Buffer...
Created Vertex Buffer...
Locking Memory...
First-chance exception at 0x0040cc8f in Vertices.exe: 0xC0000005: Access violation reading location 0x00000000.
Unhandled exception at 0x0040cc8f in Vertices.exe: 0xC0000005: Access violation reading location 0x00000000.
The program ''[3084] Vertices.exe: Native'' has exited with code 0 (0x0).
I''m not sure what the problem is because it does create a new vertex buffer to be copied in, so that isn''t what''s null. (Something looks to be null if it''s reading 0x00000000. Any ideas? Is there something I should feel really retarded for not having done? -=Lohrno

Share this post


Link to post
Share on other sites
Couple things:

First, sizeof( pData ) will return 4 (or 8 on a 64-bit machine)--the size of a pointer. You need to lock the actual size.

Second, learn to use the debugger. It can tell you so much.

I like pie.

Share this post


Link to post
Share on other sites
Hmmm... you should try to assert(pHMVB != NULL)

And do what RenderTarget said

Perhaps:
pHMVB->Lock(0,sizeof(pData),(void**)&pData,0);

Should be:
pHMVB->Lock(0,sizeof(Vertices),(void**)&pData,0);

[edited by - glassJAw on August 13, 2003 2:53:38 AM]

Share this post


Link to post
Share on other sites