Jonas R.
Jonas R.

Reputation: 28

E_INVALIDARG in D3D11

I have tried to figure out why I keep getting an E_INVALIDARG error when running my code.

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

I keep getting the E_INVALIDARG error when running the code. I myself can't seem to figure out why I get this error. If anyone could point me in the right direction I'd be greatful! :)

Upvotes: 0

Views: 1966

Answers (1)

Adam Miles
Adam Miles

Reputation: 3584

My guess would be that 'cbPerObject' is not a multiple of 16 bytes. Constant Buffers must be a multiple of 16 bytes in size.

Upvotes: 2

Related Questions