# Problem with mapping a constant buffer resource

This topic is 1405 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am implementing for my paper. However, there is a vague problem which I do not know exact reason. As debugging, the windows is frozen for a while, then goes black and it stops at code which mapping a constant buffer. The constant buffer is not null, but it is data is null after mapping.

        D3D11_MAPPED_SUBRESOURCE MappedResource3;
HR( gpImmediateContext->Map( mCBPS_ID, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource3 ) );
PS_CB_ID* pPSID = ( PS_CB_ID* )MappedResource3.pData;

char DebugString[100];
sprintf_s(DebugString,"ID_constant buffer is: %p\n", mCBPS_ID);
OutputDebugString(DebugString);
pPSID->g_iID = 0; // pPSID is null

gpImmediateContext->Unmap( mCBPS_ID, 0 );
gpImmediateContext->PSSetConstantBuffers( 3, 1, &mCBPS_ID );


Have anybody experienced this problem before? Please, help me. Thanks in advanced

##### Share on other sites

There are a couple of reasons this could happen. Are you running with the DirectX debug layer enabled? If so, you'll get some stuff in your debug output log that will probably tell you why the buffer can't be mapped. This link has more info on enabling the debug layer: http://msdn.microsoft.com/en-us/library/windows/desktop/jj200584(v=vs.85).aspx

If you already have the debug layer enabled and it's not telling you anything helpful, then I guess it would be helpful for us to see how you create the constant buffer that you're trying to map.

##### Share on other sites

Samith, thank for the reply. The error message which I get as my program is stopped is "D3D11: Removing Device.

D3D11 ERROR: ID3D11Device::RemoveDevice: Device removal has been triggered for the following reason (DXGI_ERROR_DEVICE_HUNG: The Device took an unreasonable amount of time to execute its commands, or the hardware crashed/hung. As a result, the TDR (Timeout Detection and Recovery) mechanism has been triggered. The current Device Context was executing commands when the hang occurred. The application may want to respawn and fallback to less aggressive use of the display hardware). [ EXECUTION ERROR #378: DEVICE_REMOVAL_PROCESS_AT_FAULT]"

Do you know the exact reason?

##### Share on other sites
What CPU access flags and usage do you specify when you create the buffer? It's possible the map is failing because you've told DirectX not to allow you to access the buffer data after creation. Are you using CPU_ACCESS_WRITE and USAGE_DYNAMIC? Edited by BarrySkellern