Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

D3D10_BUFFER_DESC bd;
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());
pBuffer->Unmap();

    device->IASetInputLayout(screenVertexLayout);

    device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_LINELIST);

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

    screenPass->Apply(0);

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

    temporary2DVerts.clear();
share|improve this question

1 Answer 1

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? –  Asher Einhorn Jan 11 '12 at 13:59
2  
@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? –  Asher Einhorn 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. –  Asher Einhorn Jan 11 '12 at 21:43

Your Answer

 
discard

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.