The code I am using is as follows:
struct BufferStruct{ int ResolutionHeight; int ResolutionWidth; int NumSamples; float EPSILON; float MaxViewDistance; float CameraPosition[3], CameraLook[3], CameraRight[3], CameraUp[3]; float CameraLength, CameraPixelWidth, CameraPixelHeight; int NumObjects;};ID3D11Buffer * pConstantBuffer;BufferStruct * pRenderingInfo;D3D11_BUFFER_DESC bd;ZeroMemory( &bd, sizeof(bd) );bd.Usage = D3D11_USAGE_DYNAMIC;bd.ByteWidth = sizeof(BufferStruct);bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;if( FAILED( pDev->CreateBuffer( &bd, NULL, &pConstantBuffer) ) ){ MessageBox(NULL, L"CreateBuffer failed", L"Error", MB_OK); exit(0);}D3D11_MAPPED_SUBRESOURCE MappedResource;pDevContext->Map( pConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource);pRenderingInfo = (BufferStruct *) MappedResource.pData;//code updating the data in pRenderingInfo is ommited for claritypDevContext->Unmap(pConstantBuffer, 0);
My problem is that I am getting an unhandled exception with the following Debug output:
D3D11: CORRUPTION: ID3D11DeviceContext::Map: First parameter is corrupt or NULL. [ MISCELLANEOUS CORRUPTION #13: CORRUPTED_PARAMETER1 ]
Why is this happening, and how can I fix it properly?