Lock VB access violation

Started by
12 comments, last by Sfpiano 20 years, 8 months ago

g_pD3DDevice->CreateVertexBuffer(4*sizeof(CUSTOMVERTEX), D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT, &pSB_VB, NULL); 
Then I pass a pointer to an array called stream data.

static VOID* pVertices;
pSB_VB->Lock(0, sizeof(*streamData), (void**)&pVertices, 0);
 
And it gives me an access violation on the lock call
//------------------------------------------------------------------------------------------------------The great logician Bertrand Russell once claimed that he could prove anything if given that 1+1=1. So one day, some fool asked him, "Ok. Prove that you're the Pope." He thought for a while and proclaimed, "I am one. The Pope is one. Therefore, the Pope and I are one."
Advertisement
Try and see if CreateVertexBuffer didn''t fail.
~Wave
I''d check that sizeof(*streamData) is returning the number you want. Personally I prefer vertexCount*sizeof(CUSTOMVERTEX).
Ok, this could just be that I'm at work and without my DirectX help files, but wouldn't you want to put D3DUSAGE_DYNAMIC in the CreateVertexBuffer() call instead of D3DUSAGE_WRITEONLY, which you would put in the Lock() call? And as was said, you should always have something like this:
if( FAILED(hr = pDevice->...) ){    // there is a D3DX function to convert HRESULT -> ASCII    // can't remember it though...    cout << "Couldn't Create Vertex Buffer: " << theError << endl;}


EDIT: some symantical errors

Chris Pergrossi
My Realm | "Good Morning, Dave"

[edited by - c t o a n on July 29, 2003 1:10:43 AM]
Chris PergrossiMy Realm | "Good Morning, Dave"
I actually do have an error check on that, and it''s working fine, thanks though. I tried passing 4*sizeof(CUSTOMVERTEX), but that didn''t work either, nor did switching in the dynamic and writeonly flags. The wierd thing is that the Lock call isn''t returning an error through HRESULT, but my program crashes as soon as it gets to that line.
//------------------------------------------------------------------------------------------------------The great logician Bertrand Russell once claimed that he could prove anything if given that 1+1=1. So one day, some fool asked him, "Ok. Prove that you're the Pope." He thought for a while and proclaimed, "I am one. The Pope is one. Therefore, the Pope and I are one."
1) When it gives you the access violation, go into where it''s stopped in the debugger and move the mouse pointer over the "pSB_VB" part of that line. What''s it''s value? - the buffer pointer may have become trashed.

2) sizeof() is a compile-time operator... so sizeof(*streamData) isn''t going to read from the streamData pointer points to - instead it''ll just tell you the size of the pointer.

3) Also why is the pVertices pointer declared as static? - I hope you''re not planning on locking the buffer once and using the pointer that''s been returned on subsequent calls. Very Bad Idea if you are.

--
Simon O''Connor
ex -Creative Asylum
Programmer &
Microsoft MVP

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

1) 0xcdcdcdcd

2)Then how would I pass an array of vertices into the lock function?

3)What exactly is pVertices? I''ve only had it because it has to be there, and I thought not constantly destroying and creating a new one would save some time.
//------------------------------------------------------------------------------------------------------The great logician Bertrand Russell once claimed that he could prove anything if given that 1+1=1. So one day, some fool asked him, "Ok. Prove that you're the Pope." He thought for a while and proclaimed, "I am one. The Pope is one. Therefore, the Pope and I are one."
1) - that''s not a valid pointer. That''s your problem. 0xCDCDCDCD is the value uninitialised variables are set to in debug builds.

So either:
- you''ve not assigned a anything to pSB_VB by the time that crashes,

- the CreateVertexBuffer() call has failed [the debug runtime WILL tell you why] or

- something has trashed the memory where your pointer is

--
Simon O''Connor
ex -Creative Asylum
Programmer &
Microsoft MVP

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

But isn''t the Lock call where you assign data to the VB? I ran it again, and I''m not getting any errors from the CreateVB function. Do you have any idea what could be messing with the memory there?
//------------------------------------------------------------------------------------------------------The great logician Bertrand Russell once claimed that he could prove anything if given that 1+1=1. So one day, some fool asked him, "Ok. Prove that you're the Pope." He thought for a while and proclaimed, "I am one. The Pope is one. Therefore, the Pope and I are one."
the VB itself isn''t an object yet, Lock only gives you a pointer to the memory allocated for the VB in CreateVertexBuffer.

put a breakpoint on the CreateVertexBuffer line, press F10, and see what the pSB_VB is after that. if its still 0xCDCDCDCD, CreateVB failed.

This topic is closed to new replies.

Advertisement