Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Sfpiano

Lock VB access violation

This topic is 5467 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

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

Share this post


Link to post
Share on other sites
Advertisement
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • 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!