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