So I am very new to DirectX and are trying to learn the basics but I'm running into some problem with my constant buffer. I'm trying to send a struct with three matrices to the vertex shader, but when I try to update the buffer with UpdateSubresource I get "Exception is thrown at 0x710B5DF3 (d3d11.dll) in Demo.exe: 0xC0000005: Access violation reading location 0x0000003C".
My struct:
struct Matracies
{
DirectX::XMMATRIX projection;
DirectX::XMMATRIX world;
DirectX::XMMATRIX view;
};
Matracies matracies;
Buffer creation:
ID3D11Buffer* ConstantBuffer = nullptr;
D3D11_BUFFER_DESC Buffer;
memset(&Buffer, 0, sizeof(Buffer));
Buffer.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
Buffer.Usage = D3D11_USAGE_DEFAULT;
Buffer.ByteWidth = sizeof(Matracies);
Buffer.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
D3D11_SUBRESOURCE_DATA data;
data.pSysMem = &matracies;
data.SysMemPitch = 0;
data.SysMemSlicePitch = 0;
Device->CreateBuffer(&Buffer, &data, &ConstantBuffer);
DeviceContext->VSSetConstantBuffers(0, 1, &ConstantBuffer);
Updating buffer:
DeviceContext->UpdateSubresource(ConstantBuffer, 0, 0, &matracies, 0, 0);
I am not sure what information is relevant to solve this so let me know if anything is missing.