D3D11: CORRUPTION

Started by
11 comments, last by forsandifs 13 years, 5 months ago
I am trying to map some data into an ID3D11Buffer.

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?
Advertisement
You create the buffer with the "cpu access write" flag, but D3D11_MAP_WRITE_DISCARD additionally requires the dynamic resource flag on the resource. The reason for this distinction is that the physical allocation destination of the resource may be affected by your requested usage (dynamic resources are generally kept closer to system memory than static resources).

Niko Suni

Thank you.

Is the "dynamic resource flag" not set with my line:

bd.Usage = D3D11_USAGE_DYNAMIC;
?

If not, how can I set it?
Don't forget to set bd.StructureByteStride = sizeof(D3D11_BUFFER_DESC);. Other than that it looks fine to me.

Edit: for some reason this seemed to me like cbsize or the likes. My mistake

[Edited by - LegendInStone on October 22, 2010 9:00:54 AM]
Sorry, I missed that one. Have you tried to run on the reference device?

Niko Suni

Quote:
Don't forget to set bd.StructureByteStride = sizeof(D3D11_BUFFER_DESC)


I think this is only needed for structured buffers and then it should be sizeof(BufferStruct).

Two shots in the dark from me:
Maybe sizeof(BufferStruct) is not a multiple of 16? (Although I think this should be checked by CreateBuffer.)
Maybe something is wrong with the DeviceContext?
Please post your HLSL constant buffer as well as the packing table for the constant buffer. You can get the packing table by using fxc on the command line to compile the shader.

This will help us see how big HLSL expects the constant buffer to be as well as how the memory is laid out. I think that your C++ struct may not quite match.
//Edited after DieterVW's post.

Thank you for all the replies folks.

macnihilist: I thought it might be the multiple of 16 issue, but using sizeof(BufferStruct) + 16 - sizeof(BufferStruct) % 16 ; doesn't solve the problem.

//DieterVW, I am working on posting the code you requested.
DieterVW,

This is my HLSL constant buffer:

cbuffer RenderingInfo : register(b0){	int ResolutionHeight;	int ResolutionWidth;	int NumSamples;	float EPSILON;		float MaxViewDistance;		float3 CameraPosition, CameraLook, CameraRight, CameraUp;	float CameraLength, CameraPixelWidth, CameraPixelHeight;	int NumObjects;}


About the command line fxc request. I don't know how to compile using the command line in VC++, and I'm not familiar with fxc. (I use f5 to compile.)

However, I don't think I have yet told the GPU to assign any information to the HLSL constant buffer, i.e. I haven't set the constant buffer to register b0. So I don't understand how there could be a conflict there.


Further information:

I've gone as far as commenting out the code I posted in the OP and I still get an unhandled exception, this time saying nothing about a D3D11: CORRUPTION, so its not the code I posted that's causing the error. This program is a small iteration on a prior version of my program that worked well, so I will try and pinpoint what part of the added code is causing the problem.
Sorry if I'm spamming, but there's an update to my progress which might help those who are kindly trying to help with this problem.

The exception error that occured when the OP code was commented out was due to calling a NULL pointer earlier in my code. This fixed, the exception error no longer occurred when I commented out the code in the OP.

HOWEVER, upon uncommenting the Map call quoted in the OP, I again got the same D3D11: CORRUPTION error. So there were two bugs in fact, one of which was trivial, and also unrelated to this problem, and another which is causing this D3D11: CORRUPTION problem which remains a mystery to me.

[Edited by - forsandifs on October 22, 2010 2:02:16 PM]

This topic is closed to new replies.

Advertisement