I'm writing a simple class to draw all the debugging lines I have in my scene at once.

The code in the draw loop is this so far: (If I put for example, 2 instead of temporary2DVerts.size() where I have marked with //THIS LINE, the code works fine.) when I run the code below the line breaks //HERE. Access violation reading location 0x00000000. seems like the create buffer line is not working, but why? what's the solution?

bd.Usage = D3D10_USAGE_DYNAMIC;
bd.ByteWidth = sizeof(VERTEX) * temporary2DVerts.size();// THIS LINE
bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
bd.MiscFlags = 0;

device->CreateBuffer(&bd, NULL, &pBuffer);

void* pVoid;

pBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &pVoid); //HERE
memcpy(pVoid, &temporary2DVerts[0], sizeof(temporary2DVerts[0]) * temporary2DVerts.size());



    UINT stride = sizeof(VERTEX);
    UINT offset = 0;
    device->IASetVertexBuffers(0, 1, &pBuffer, &stride, &offset);


    device->Draw(temporary2DVerts.size(), 0);


1 Answer 1


It is very likely that device->CreateBuffer is failing, resulting in pBuffer being NULL. You need to check the return value.

  • \$\begingroup\$ yeah that is what's happening. but why? \$\endgroup\$ Commented Jan 11, 2012 at 13:59
  • 2
    \$\begingroup\$ @AsherEinhorn: well I don't know the return value, you do :-) Which one is it? \$\endgroup\$ Commented Jan 11, 2012 at 14:33
  • \$\begingroup\$ Is temporary2DVerts empty? If so, I wouldn't be surprised if CreateBuffer refuses to create a zero-sized buffer. \$\endgroup\$ Commented Jan 11, 2012 at 18:54
  • \$\begingroup\$ how do I check the return value? \$\endgroup\$ Commented Jan 11, 2012 at 21:36
  • \$\begingroup\$ @NathanReed I think you were right, for a brief moment when the program starts there were no verts! thanks. \$\endgroup\$ Commented Jan 11, 2012 at 21:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .