Skip to main content
gamedev.net
🔒 Locked

Please help; VertexBuffer

Started by Saandman Oct 4, 2002 at 7:37 PM 4 replies 350+ views
Original Post
Saandman
Saandman
I get an access violation when trying to lock the vertex buffer. I have wrapped the original function, bah look here:

// I call this function:
D3DCreateVertexBuffer(g_pVertexBuffer, yadayada, ...);

// and now i want to lock it and copy some shit into it
D3DFillVertexBuffer(g_pVertexBuffer, &Verts);

// And here's the function
/////////////////////////////////////////////////
bool D3DFillVertexBuffer(IDirect3DVertexBuffer8 *vBuffer, void *vertices)
{
	BYTE *memPtr;	// pointer to memory in vertex buffer

	// lock vertex buffer 
	if (FAILED(vBuffer->Lock(0, 0, (BYTE **)&memPtr, 0)))
		return false;

	// copy memory
    memcpy(memPtr, vertices, sizeof(vertices));

	// unlock vertex buffer
	if (FAILED(vBuffer->Unlock()))
		return false;

	return true;
}
  
Problem is, as I said, I get an access error reading memory location.. looking at debug values, it says memPtr is a bad pointer.. why, how can it be? has this anything to do with the error? i have the feeling i have missed something..another thing, the vertexbuffer object is still NULL (0x000000000whatever) after creating it in the first function.. ?!?!?! Thanks..Help.. /Sandman [edited by - Saandman on October 4, 2002 8:49:27 PM]
________pro.gram.mer - an organism that turns caffeine into code
masonium
masonium
First of all, make sure vBuffer is actually created with enough memory to copy the data. If vBuffer is NULL when you pass it to your Fill function, then the call definitiely won''t work. Second, you might want to change memPtr to void* if only for the simple reason that most implementations use it. Third, when you''re using memcpy, your sizeof(vertices) is always going to be 4 because sizeof(vertices) will be the same as sizeof(void*), which is 4. You need another parameter in your function that has the size of the vertex data.

''There''s something out there....something stupid...''
- Daria

DirectInput8 with the Keyboard , DirectInput8 with the Mouse , Using DirectX Audio 8
Saandman
Saandman
Thanks for your help, I tracked it down to that vBuffer == NULL. I thought it was weird!

But what is wrong.. Here's the function I call to create the buffer:


bool D3DCreateVertexBuffer(IDirect3DVertexBuffer8 *vBuffer, ULONG NumVertices, long VertexSize, DWORD fvf)
{
// create the vertex buffer
if (FAILED(g_pD3DDevice->CreateVertexBuffer(VertexSize * NumVertices, 0, fvf,
D3DPOOL_DEFAULT, &vBuffer)))
return false;

return true;
}


Any ideas? Because if I skip that call and call the original function instead, everything works out fine... It's my evil func screwing it up muahaha!

Fuck.. =)

/Sandman


[edited by - Saandman on October 5, 2002 7:09:11 AM]
________pro.gram.mer - an organism that turns caffeine into code
Darrell L
Darrell L
Change vBuffer in your func prototype to be a pointer to a pointer, e.g., **vBuffer instead of *vBuffer. Then just pass vBuffer to CreateVertexBuffer instead of &vBuffer.

You''ll have to also change your call to your func to pass the address of an IDirect3DDevice8 pointer.
Darrell L
Darrell L
You might also want to consider using PDIRECT3DVERTEXBUFFER8 or LPDIRECT3DVERTEXBUFFER8 in place of *IDirect3DVertexBuffer8 to help with readability. See the main page on IDirect3DVertexBuffer8 in the MSDN for how they''ve typdef''d the struct.
Saandman
Saandman
Thanks alot mate, that pp solved it!

/Sandman
________pro.gram.mer - an organism that turns caffeine into code

Topic Locked

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

Sign in to reply to this topic.