Jump to content
  • Advertisement
Sign in to follow this  
forsandifs

D3D11: CORRUPTION

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 clarity

pDevContext->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?

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
//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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!