D3D11中的E_INVALIDARG

时间:2015-04-23 07:15:34

标签: c++ visual-studio-2013 directx-11

我试图找出运行代码时出现E_INVALIDARG错误的原因。

    ID3D11Buffer * cbPerObjectBuffer;
cbPerObject cbPerObj;

cbPerObjectBuffer = 0;

D3D11_BUFFER_DESC cbbd;
ZeroMemory( & cbbd, sizeof(D3D11_BUFFER_DESC));

cbbd.Usage = D3D11_USAGE_DEFAULT;
cbbd.ByteWidth = sizeof(cbPerObject);
cbbd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
cbbd.CPUAccessFlags = 0;
cbbd.MiscFlags = 0;
cbbd.StructureByteStride = 0;

hr = device - > CreateBuffer( & cbbd, NULL, & cbPerObjectBuffer);
if (hr == E_INVALIDARG) {
  MessageBox(0, L "[CBPEROBJECTBUFFER] An invalid parameter was passed to the returning function.", L "Error", MB_OK);
  return;
} else if (hr == E_OUTOFMEMORY) {
  MessageBox(0, L "[CBPEROBJECTBUFFER] Out of memory", L "Error", MB_OK);
  return;
} else if (FAILED(hr)) {
  MessageBox(0, L "[CBPEROBJECTBUFFER] An unknown error occured", L "Error", MB_OK);
  return;
}

运行代码时,我一直收到E_INVALIDARG错误。我自己似乎无法弄清楚为什么我会收到这个错误。 如果有人能指出我正确的方向,我会很高兴! :)

1 个答案:

答案 0 :(得分:2)

我的猜测是' cbPerObject'不是16个字节的倍数。常量缓冲区的大小必须是16个字节的倍数。