#### Archived

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

# How to use vertex buffers?

This topic is 6562 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

After a bizarre problem where moving the data for my objects from an array of 24 vertices to a list of 6 sides with 4 vertices each caused the frame rate to drop to less than 1 per second when viewing that object, I decided to try again with a vertex buffer for each object, 24 vertices in size to hold all the corners of a cube/cuboid. (Note: I do know this is not very efficient at all, but I figured it would do until I was used to vertex buffers). However, it seems to inexplicably crash when I call 'lock' on the buffer to write the data into the buffer. Here's the code:
// Make our vertex buffer
D3DVERTEXBUFFERDESC vbdesc;

DX_INIT_STRUCT(vbdesc); // clears it and sets dwSize
vbdesc.dwCaps        = 0L;
vbdesc.dwFVF         = D3DFVF_VERTEX;
vbdesc.dwNumVertices = 24;
// I have tried both with and without the following line,
//   but it makes no difference
//vbdesc.dwCaps /= D3DVBCAPS_SYSTEMMEMORY;

// Create a clipping-capable vertex buffer.
if (FAILED(DirectDraw.GetlpD3D()->CreateVertexBuffer(&vbdesc,
&vbuffer, 0, NULL)))
throw "CreateVertexBuffer() failed.";

D3DVERTEX* bufferMemory;

if (FAILED(vbuffer->Lock(DDLOCK_WAIT, (VOID**)&bufferMemory, NULL)))
throw "Lock failed";


If one of the calls failed, my exception handling should log the error message to my logfile. However, I am getting some other type of crash, cos it drops through to the (...) catch handler. If I comment out the lock (and the corresponding unlock, not shown above) line, it 'works' fine (of course, it doesn't render a thing ) What am I missing? Something obvious, I'm sure. Any ideas would be appreciated. Also, advice on a good way to store object vertex info while maintaining some sort of object-orientation would be handy. I'm using DX6.1, MSVC5, and an original Voodoo (ick, I know), for what it's worth. Edited by - Kylotan on 3/9/00 8:57:31 PM