Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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);

share|improve this question
up vote 1 down vote accepted

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

share|improve this answer
yeah that is what's happening. but why? – SirYakalot Jan 11 '12 at 13:59
@AsherEinhorn: well I don't know the return value, you do :-) Which one is it? – sam hocevar Jan 11 '12 at 14:33
Is temporary2DVerts empty? If so, I wouldn't be surprised if CreateBuffer refuses to create a zero-sized buffer. – Nathan Reed Jan 11 '12 at 18:54
how do I check the return value? – SirYakalot Jan 11 '12 at 21:36
@NathanReed I think you were right, for a brief moment when the program starts there were no verts! thanks. – SirYakalot Jan 11 '12 at 21:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.