Sign in to follow this  
canonind

Adding Vertices to buffer

Recommended Posts

I have a class for an object which creates the vertex buffer and puts some vertices inside. Then I want to add more vertices to the vertex buffer from the WinMain.cpp by using the code below.

[code]

void initgraphics()
{
myShip.VBuffOperations(v_buffer,d3ddev);
myShip.IBuffOperations(i_buffer,d3ddev);

VertexSize = myShip.returnVertexSize();
VertexNumber = myShip.returnVertexNumber();

CUSTOMVERTEX boxVertices [] =
{
//Side1
{-10.0f,1.0f,-1.0f,D3DXVECTOR3(1.0f,0.0f,0.0f)},
{-10.0f,1.0f,1.0f,D3DXVECTOR3(1.0f,0.0f,0.0f)},
{-10.0f,-1.0f,-1.0f,D3DXVECTOR3(1.0f,0.0f,0.0f)},
{-10.0f,-1.0f,1.0f,D3DXVECTOR3(1.0f,0.0f,0.0f)},
};

VOID* box_pVoid;
v_buffer->Lock(0,0,static_cast<void**>(&box_pVoid),D3DLOCK_NOOVERWRITE);
memcpy(&box_pVoid,&boxVertices,sizeof(boxVertices));
v_buffer->Unlock();

short boxIndices [] =
{
52,53,54,
53,54,55
};

VOID* box_Indice;
i_buffer->Lock(0,0,static_cast<void**>(&box_Indice),D3DLOCK_NOOVERWRITE);
memcpy(&box_Indice,&boxIndices,sizeof(boxIndices));
i_buffer->Unlock();

initLight();
}
[/code]

However I get a runtime error like "stack around the variable 'box_Indice' was corrupted. I guess it's related to the lock of the buffer. But as far as I understand, passing 0 to the first 2 parameters means lock the whole buffer and D3DLOCK_NOOVERWRITE flag should make sure that the present vertices stay untouched. So everything looks fine to me. What am I missing?

Share this post


Link to post
Share on other sites
No overwrite means you're appending to the buffer so you shouldn't overwrite (hence the name) the memory used by previous vertexes. It doesn't give you a new block of memory. You need D3DLOCK_DISCARD for what you wish to do - that gives you a new region of memory and the old memory will be automatically freed when any draw commands using it have finished.

Share this post


Link to post
Share on other sites
Your "VOID* box_pVoid" should be "VOID* box_pVoid = NULL" too, as should "VOID* box_Indice". And make sure that you're using discard on both locks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this