Jump to content
  • Advertisement
Sign in to follow this  
LevyDee

Hitting Unhandled exception on IDirect3DVertexBuffer9::Unlock()

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

As the title says, I am hitting an exception, but I cant figure out why. I am writing a function to subdivide the information in a vertex buffer(double the number of triangles for each level of subdivision)


void SubDivideSurface(int levels, IDirect3DDevice9* device)
{
//Testing. Assuming levels is 1

//Copy vertex data
void* vertData;
_vertexBuffer->Lock(0, 0, &vertData, 0);
LWVERTEX* vertDataCopy = new LWVERTEX[sizeof(LWVERTEX) * _verticeCount];
memcpy(vertDataCopy, vertData, sizeof(LWVERTEX) * _verticeCount);
_vertexBuffer->Unlock();

int oldVertCount = _verticeCount;
_verticeCount *= (levels + 1);
if(device->CreateVertexBuffer((sizeof(LWVERTEX) * _verticeCount),
0,
0,
D3DPOOL_MANAGED,
&_vertexBuffer,
0) != D3D_OK)
ErrorMessenger::ReportMessage("Failed to create vertex buffer", __FILE__, __LINE__);

//Hold the new buffer info
LWVERTEX* newBufferInfo = new LWVERTEX[sizeof(LWVERTEX) * _verticeCount];

//For each triangle
for(int i = 0; i < oldVertCount; i += 3)
{

//Find hypotenuse
D3DXVECTOR3 hypoVec1;
D3DXVECTOR3 hypoVec2;
D3DXVECTOR3 oppHypotenuse = _FindHypotenuse(vertDataCopy.position, vertDataCopy[i + 1].position, vertDataCopy[i + 2].position, &hypoVec1, &hypoVec2);

//Find the midpoint on the hypotenuse line
D3DXVECTOR3 midPoint = D3DXVECTOR3(((hypoVec1.x + hypoVec2.x) / 2), ((hypoVec1.y + hypoVec2.y) / 2), ((hypoVec1.z + hypoVec2.z) / 2));

//New split triangle one
newBufferInfo[(i * 2)].position = oppHypotenuse;
newBufferInfo[(i * 2) + 1].position = hypoVec1;
newBufferInfo[(i * 2) + 2].position = midPoint;

//New split triangle two
newBufferInfo[(i * 2) + 3].position = oppHypotenuse;
newBufferInfo[(i * 2) + 4].position = hypoVec2;
newBufferInfo[(i * 2) + 5].position = midPoint;
}

//Set new vert data
void* newVertData;
_vertexBuffer->Lock(0, 0, &newVertData, 0);
memcpy(vertData, (void*)newBufferInfo, (sizeof(LWVERTEX) * _verticeCount));

//Exception occurs here
_vertexBuffer->Unlock();
}

Share this post


Link to post
Share on other sites
Advertisement
I solved my problem, I was copying to an incorrect buffer. I ran this through PIX and it seems to be working as expected =) good day all!

Share this post


Link to post
Share on other sites
For future reference, it's helpful to say exactly what the error you get is (E.g. "Access Violation reading 0x00000000"), since that can give a clue about the cause (E.g. an access violation reading an address near 0x00000000 means you probably tried to dereference a null pointer).

Share this post


Link to post
Share on other sites

since that can give a clue about the cause (E.g. an access violation reading an address near 0x00000000 means you probably tried to dereference a null pointer).


I would like to think my debugging skills could find a simple problem like that =P

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!