Sign in to follow this  

CreateBuffer unhandled exception

This topic is 2389 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

Why am I getting an unhandled exception when I create a buffer as follows?

[code]
D3D11_BUFFER_DESC BufferDesc;
ZeroMemory(&BufferDesc, sizeof(BufferDesc));
BufferDesc.ByteWidth = Length * FormatSize;
BufferDesc.BindFlags = D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_SHADER_RESOURCE;
BufferDesc.Usage = D3D11_USAGE_DEFAULT;
pD3DSys->pGetDevice()->CreateBuffer(&BufferDesc, &SRData, &pBuffer);
[/code]

Where Length = 16384 and FormatSize = 4 meaning that BufferDesc.ByteWidth = 65536.

Please note that when Length = 8191 I do not get the same error.

I could swear I've created larger buffers than that in the past. And I would be very surprised if it means I'm running out of memory on my GPU as I have 1gb memory on it and the other buffers I create before that are small.

EDIT: the messages I am getting are like follows.

[code]
First-chance exception at 0x652d8c1a in 034.exe: 0xC0000005: Access violation reading location 0x002fe000.
Unhandled exception at 0x652d8c1a in 034.exe: 0xC0000005: Access violation reading location 0x002fe000.
[/code]

Share this post


Link to post
Share on other sites
[quote name='forsandifs' timestamp='1306926893' post='4818234']
Why am I getting an unhandled exception when I create a buffer as follows?

[code]
D3D11_BUFFER_DESC BufferDesc;
ZeroMemory(&BufferDesc, sizeof(BufferDesc));
BufferDesc.ByteWidth = Length * FormatSize;
BufferDesc.BindFlags = D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_SHADER_RESOURCE;
BufferDesc.Usage = D3D11_USAGE_DEFAULT;
pD3DSys->pGetDevice()->CreateBuffer(&BufferDesc, &SRData, &pBuffer);
[/code]

Where Length = 16384 and FormatSize = 4 meaning that BufferDesc.ByteWidth = 65536.

Please note that when Length = 8191 I do not get the same error.

I could swear I've created larger buffers than that in the past. And I would be very surprised if it means I'm running out of memory on my GPU as I have 1gb memory on it and the other buffers I create before that are small.

EDIT: the messages I am getting are like follows.

[code]
First-chance exception at 0x652d8c1a in 034.exe: 0xC0000005: Access violation reading location 0x002fe000.
Unhandled exception at 0x652d8c1a in 034.exe: 0xC0000005: Access violation reading location 0x002fe000.
[/code]
[/quote]

Enable Direct3D debugging. It should tell you more about the function call. Have you checked your code with a debugger to see if the pointers are good?

Share this post


Link to post
Share on other sites
Thanks for your reply. :)

I have D3D debugging turned on.

About the pointers, I replaced &SRData with NULL in the code above and the exception went away which suggests that its not a buffer problem but a problem with the data I'm trying to put into the buffer?

Here is the entire function I use to create a buffer.

[code]
GPUBufferClass::GPUBufferClass(D3DSysClass * pD3DSysPassed, int LengthPassed, int FormatSize, void * pData, DXGI_FORMAT FormatPassed)
{
pD3DSys = pD3DSysPassed;
Length = LengthPassed;
Format = FormatPassed;

D3D11_SUBRESOURCE_DATA SRData;
ZeroMemory(&SRData, sizeof(SRData));
SRData.pSysMem = pData;

D3D11_BUFFER_DESC BufferDesc;
ZeroMemory(&BufferDesc, sizeof(BufferDesc));
BufferDesc.ByteWidth = Length * FormatSize;
BufferDesc.BindFlags = D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_SHADER_RESOURCE;
BufferDesc.Usage = D3D11_USAGE_DEFAULT;
pD3DSys->pGetDevice()->CreateBuffer(&BufferDesc, &SRData, &pBuffer);
}
[/code]

The following code contains the creation of the data and the calling of the above.

[code]
pRandomSeeds1 = new std::vector<UINT32>;

for(unsigned int i=0; i < 16384; i++){ pRandomSeeds1->push_back( pRNGPassed->RandInt() ); }

pRandomSeeds1Buffer = new GPUBufferClass(pD3DSys,pRandomSeeds1->size(), sizeof(UINT32), &(pRandomSeeds1)[0], DXGI_FORMAT_R32_UINT);
[/code]

Share this post


Link to post
Share on other sites
Hi,

your problems seems curious as I can't find a problem related to the code.

I found a class similar to your class [url="http://www.codeproject.com/KB/directx/DirectX11ComputeShaders.aspx?msg=3360367&display=Mobile"]here[/url] and only difference there was a line "desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;"


Shouldn't matter though.


[font="Courier New"]Cheers![/font]

[font="Courier New"][EDIT] Didn't notice that your std::vector was a pointer. I think your culprit is there. The address of the first element isn't correct.[/font] Edited by kauna

Share this post


Link to post
Share on other sites
Sounds to me like you may have hit some sort of driver issue, since the code works if the buffer size is different. Are your drivers up to date?

What's the full call stack when you get that access violation?

Is that read location that gets output on the access violation message (0x002fe000 in that first run) inside your std::vector or just off the end or somewhere else entirely? I'm suspicious that something is reading past the end of a buffer because the address is aligned to a 4k page boundary.

Share this post


Link to post
Share on other sites
[code]
&(pRandomSeeds1)[0]
[/code]

That looks wrong. You probably meant this (extra parentheses added for emphasis), which takes the address of the first element in the vector:

[code]
&((*pRandomSeeds1)[0])
[/code]

To be sure, you could assign your pointer to a const UINT32* variable to make sure the pointer is of the right type.

Share this post


Link to post
Share on other sites

This topic is 2389 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this