Sign in to follow this  

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.


void initgraphics()

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

CUSTOMVERTEX boxVertices [] =

VOID* box_pVoid;

short boxIndices [] =

VOID* box_Indice;


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