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 trying to make instanced geometry in Direct3D11, and the ID3D11DeviceContext1->Map() call is failing with the very helpful error of "Invalid Parameter" when I'm attempting to update the instance buffer.

The buffer is declared as a member variable:

Microsoft::WRL::ComPtr<ID3D11Buffer> m_instanceBuffer;

Then I create it (which succeeds):

D3D11_BUFFER_DESC instanceDesc;
ZeroMemory(&instanceDesc, sizeof(D3D11_BUFFER_DESC));
instanceDesc.Usage = D3D11_USAGE_DYNAMIC;
instanceDesc.ByteWidth = sizeof(InstanceData) * MAX_INSTANCE_COUNT;
instanceDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
instanceDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
instanceDesc.MiscFlags = 0;
instanceDesc.StructureByteStride = 0;

DX::ThrowIfFailed(d3dDevice->CreateBuffer(&instanceDesc, NULL, &m_instanceBuffer));

However, when I try to map it:

DX::ThrowIfFailed(d3dContext->Map(m_instanceBuffer.Get(), 0, D3D11_MAP_WRITE, 0, &inst));

The map call fails with E_INVALIDARG. Nothing is NULL incorrectly, and this being one of my first D3D apps I'm currently stumped on what to do next to track it down. I'm thinking I must be creating the buffer incorrectly, but I can't see how. Any input would be appreciated.

share|improve this question
Have you tried turning on the debug layer when you create the device, and see if you get any interesting warning messages? The messages will appear in Visual Studio's Output pane, if you run your app in the debugger. – Nathan Reed Nov 29 '12 at 5:45
Thanks, that pointed out the error immediately. I had read about the debug layer, then forgot about it. Won't again. – Donnie Nov 29 '12 at 6:50
up vote 4 down vote accepted

@Nathan's debug layer tip pointed this out fast - so, turn on the debug layer when debugging D3D code.

The problem was that the MapType needed to be D3D11_MAP_WRITE_DISCARD (or D3D11_MAP_WRITE_NO_OVERWRITE, but that wasn't appropriate for me) because the buffer was created as BUFFER_DYNAMIC.

I'm sure that was documented somewhere, but I completely missed it.

share|improve this answer

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.