Jump to content
  • Advertisement
Sign in to follow this  
canonind

Adding Vertices to buffer

This topic is 2552 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 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.



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();
}


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
Advertisement
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
I tried it, but I'm still getting the "stack around" error. Is the way I'm locking the vertex and index buffers OK?

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!