Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Lock Access Violation Help


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 noodleBowl   Members   -  Reputation: 207

Like
0Likes
Like

Posted 24 October 2013 - 07:53 PM

Hey I was wondering if anyone could shed some light onto this one

 

I'm trying to lock my vertex buffer and index buffer like so:

vBuffer->Lock(currentVertexDataAmount, vertexBufferSize - currentVertexDataAmount, (void**)&vertices, bufferLockFlag);
iBuffer->Lock(currentIndexDataAmount, indexBufferSize - currentIndexDataAmount, (void**)&indices, bufferLockFlag);
	

But I always get a Access Violation on the vertex buffer unlock call after the second run though. It definitely has something to do with the offset and sizeToLock params.

On the second run through there is a starting offset of 96 (One quad vertex data worth) and 192 (2 quads vertex data worth) as the sizeToLock.

If I set the params to 0, 0 it works. But I would like to only lock what I need

 

Any ideas? Am I just using the offset and sizeToLock params wrong or is everything wrong?

The lock flag is set to NOOVERWRITE at the start.

 

Here is how this code is being used

        vBuffer->Lock(currentVertexDataAmount, vertexBufferSize - currentVertexDataAmount, (void**)&vertices, bufferLockFlag);
	iBuffer->Lock(currentIndexDataAmount, indexBufferSize - currentIndexDataAmount, (void**)&indices, bufferLockFlag);
	
	for(std::vector<quad>::iterator i = drawData.begin(); i != drawData.end(); i++)
	{
                //If the vertex buffer is full
		if(vertexBufferSize - currentVertexDataAmount == 0)
                {

                vBuffer->Unlock(); //<----- [ BREAK HAPPENS HERE after second run through ]
                iBuffer->Unlock();

                /*
                   Draw what needs to be drawn;
                   Set the positions of the buffers and data amount used to 0;
                   change the lock flag to DISCARD;
                */

                vBuffer->Lock(currentVertexDataAmount, vertexBufferSize - currentVertexDataAmount, (void**)&vertices, bufferLockFlag);
                iBuffer->Lock(currentIndexDataAmount, indexBufferSize - currentIndexDataAmount, (void**)&indices, bufferLockFlag);
                  
                /*change the lock flag back to NOOVERWRITE*/
                }
                 

                //Fill the vertex buffer
		vertices[currentVertexBufferPosition] = (*i).verts[0];
		vertices[currentVertexBufferPosition + 1] = (*i).verts[1];
		vertices[currentVertexBufferPosition + 2] = (*i).verts[2];
		vertices[currentVertexBufferPosition + 3] = (*i).verts[3];
                
                //Fill the vertex buffer
		indices[currentIndexBufferPosition] = currentVertexBufferPosition;
		indices[currentIndexBufferPosition + 1] = currentVertexBufferPosition + 1;
		indices[currentIndexBufferPosition + 2] = currentVertexBufferPosition + 2;
		indices[currentIndexBufferPosition + 3] = currentVertexBufferPosition + 3;
		indices[currentIndexBufferPosition + 4] = currentVertexBufferPosition;
		indices[currentIndexBufferPosition + 5] = currentVertexBufferPosition + 2;
                
                //Increase the data amounts
		currentVertexBufferPosition += 4;
		currentIndexBufferPosition += 6;
		currentVertexDataAmount += VERTEX_DATA_AMOUNT_PER_QUAD;
		currentIndexDataAmount += INDEX_DATA_AMOUNT_PER_QUAD;
                
                //Debug stuff
		std::cout<<"Added quad<> Y:"<<(*i).verts[0].y<<std::endl;
		std::cout<<"VB Pos: "<<currentVertexBufferPosition<<"; IB Pos: "<<currentIndexBufferPosition<<std::endl;
		getchar();

	}

	vBuffer->Unlock();
	iBuffer->Unlock();
        drawData.clear();

Edited by noodleBowl, 24 October 2013 - 10:34 PM.


Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS