Jump to content
  • Advertisement
Sign in to follow this  
Ripiz

DX11 [C++, DX11] Creating Index Buffer problem

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

Hello,

I am trying to create and initialize index buffer with D3D11_USAGE_DEFAULT flag for better performance, however program crashes with following error(s):
First-chance exception at 0x6cb7100c in Client11_Debug.exe: 0xC0000005: Access violation reading location 0x02f56000.
Unhandled exception at 0x6cb7100c in Client11_Debug.exe: 0xC0000005: Access violation reading location 0x02f56000.

Here's my code:

uint16 *pIndexData = new uint16[127 * 127 * 2 * 3];
for(uint8 x = 0; x < 127; x++) {
for(uint8 y = 0; y < 127; y++) {
*pIndexData++ = x + y * 128;
*pIndexData++ = x + 1 + y * 128;
*pIndexData++ = x + 1 + (y + 1) * 128;

*pIndexData++ = x + y * 128;
*pIndexData++ = x + 1 + (y + 1) * 128;
*pIndexData++ = x + (y + 1) * 128;
}
}

D3D11_SUBRESOURCE_DATA InitData;
InitData.pSysMem = pIndexData;

ZeroMemory(&bufferDescription, sizeof(bufferDescription));
bufferDescription.Usage = D3D11_USAGE_DEFAULT;
bufferDescription.ByteWidth = sizeof(uint16) * 127 * 127 * 2 * 3;
bufferDescription.BindFlags = D3D11_BIND_INDEX_BUFFER;
bufferDescription.CPUAccessFlags = 0;
device->CreateBuffer(&bufferDescription, &InitData, &bufferIndex); // crashes here
/*
device == 0x002e78d0
bufferIndex == 0x00000000
pIndexData == 0x02f4f884
*/


Does anyone know what I am doing wrong? Let me know if I forgot any information. Thank you in advance.

Share this post


Link to post
Share on other sites
Advertisement
See the problem: uint16 *pIndexData = new uint16[...];
pIndexData++;
pIndexData++;
pIndexData++;
pIndexData++;
pIndexData++;
InitData.pSysMem = pIndexData;
You're passing a pointer to the end of your data block instead of the beginning.

Share this post


Link to post
Share on other sites
I didn't actually spot that bug from your code straight up -- the other details that you posted helped. When I saw this, I knew that something was suss with the index data and looked closely at that logic:
[font="Courier New"]...pIndexData == 0x02f4f884[/font] .. supposed to be a ~190KB allocation starting at this address
[font="Courier New"]reading location 0x02f56000[/font] .. but not allowed to access a value that's 25KB into the allocation??

So those hexidecimal numbers can be useful when sometimes ;)

Share this post


Link to post
Share on other sites
[font=arial, verdana, tahoma, sans-serif][size=2]Interesting logic I'd say, thank you for details and information. I'll try to use this next time I encounter strange problem.[/font]

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!