Archived

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

Horn

Vertex buffers problems

Recommended Posts

I'm just learning DirectX and I'm having problems getting the vertex buffers to work. It crashes when I memcpy the data into the buffer after locking it.
      
if(FAILED(device->CreateVertexBuffer(sizeof(vertices),D3DUSAGE_WRITEONLY,D3DFVF_CUSTOMVERTEX,D3DPOOL_MANAGED,&buffer)))
	MessageBox(NULL,"Bad create","A",MB_OK);
if(FAILED(buffer->Lock(0,0,(byte**)&ptr,0)))
	MessageBox(NULL,"Bad Lock","A",MB_OK);
memcpy(ptr,vertices,sizeof(vertices));
buffer->Unlock();
  
I tried using a dynamic array but when that didn't work I used a fixed sized array but I still ran into the same problem.
  
D3DVERTEX vertices[128*128*6];
    
[edited by - Horn on November 4, 2002 5:55:46 PM]

Share this post


Link to post
Share on other sites
Here''s some ideas:

(1) Use D3DPOOL_DEFAULT instead of D3DPOOL_MANAGED.
(2) Initialize ptr to 0 (or NULL) before the lock call.
(3) Check your FVF variable D3DFVF_CUSTOMVERTEX to make sure it matches the footprint of D3DVERTEX.
(4) Try this line instead of your memcpy line:


CopyMemory(ptr, (void*)vertices, sizeof(vertices));


One of the above may solve your problem.

--Neil



----------------------
Check out my game demo and resume at
www.fivestory.com/projects/game.

Share this post


Link to post
Share on other sites
Alright I have that working but I''ve ran into another problem. What I''m doing is creating a heightmap and stuffing the vertices into a buffer. The height map is 128x128 so I''m creating 96774 vertices. It seems to put them into the stream properly but there not there when I try to draw them (dx tells me that the streams don''t have the required number of vertices).


  
//48000 = 16000 * 3

app->device->DrawPrimitive(D3DPT_LINELIST,0,16000);
app->device->DrawPrimitive(D3DPT_TRIANGLELIST,48000,3);


Is there a limit to the number of vertices than can be in a buffer or am I fudging it up somewhere else?

Share this post


Link to post
Share on other sites
This is a common error when dealing with DrawPrimitive() and related functions. There''s probably just a discrepancy in your code between the size of your VB, the number of vertices you''re stuffing into the VB, and the number of vertices that your DrawPrimitive() call references.

My advice: bring your heightmap down to a much smaller size for debugging purposes and fiddle around with your numbers.

--Neil.

----------------------
Check out my game demo and resume at
www.fivestory.com/projects/game.

Share this post


Link to post
Share on other sites