CreateBuffer unhandled exception

Started by
5 comments, last by forsandifs 12 years, 10 months ago
Why am I getting an unhandled exception when I create a buffer as follows?


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);


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.


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.
Advertisement

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


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);


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.


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.



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


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);
}


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


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);
Hi,

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

I found a class similar to your class here 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]
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.

&(pRandomSeeds1)[0]


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


&((*pRandomSeeds1)[0])


To be sure, you could assign your pointer to a const UINT32* variable to make sure the pointer is of the right type.
Thank you very much! That solves it. :)

This topic is closed to new replies.

Advertisement