Hello,
I'm trying to read the raw texture values of textures in DirectX 11 and I've run into a bit of a weird problem. My code seems to work fine for 512x512 textures but as soon as I try reading data from a 1024x1024 texture, I get a crash at the memcpy() line.
Here's relevant code:
// set up the loaded textures as subresources
D3D11_SUBRESOURCE_DATA* subresources = new D3D11_SUBRESOURCE_DATA[texCount];
// copy the loaded texture data into the subresource structures
for(UINT i = 0; i < texCount; ++i) {
D3D11_MAPPED_SUBRESOURCE mappedSubResource;
HRESULT mapResult = p_deviceContext_->Map(textures[i], 0, D3D11_MAP_READ, 0, &mappedSubResource);
if(FAILED(mapResult)) {
MessageBox(NULL, L"Failed mapping a subresource.", L"Error", 0);
return;
}
// size of the texture's data defined by the length of a single row of data * the total number of rows (texture height)
subresources[i].pSysMem = new BYTE[mappedSubResource.RowPitch * texHeight];
memcpy(const_cast<void*>(subresources[i].pSysMem), mappedSubResource.pData, mappedSubResource.RowPitch * texHeight);
subresources[i].SysMemPitch = mappedSubResource.RowPitch;
subresources[i].SysMemSlicePitch = mappedSubResource.DepthPitch;
p_deviceContext_->Unmap(textures[i], 0);
}