Reputation: 115
For some reason, the code below crashes when I try to create the 1d texture.
D3D11_TEXTURE1D_DESC desc;
ZeroMemory(&desc, sizeof(D3D11_TEXTURE1D_DESC));
desc.Width = 64;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.Format = DXGI_FORMAT_R8G8B8A8_SNORM;
desc.Usage = D3D11_USAGE_STAGING;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
HRESULT hr = D3DDev_0001->CreateTexture1D(&desc, NULL, &texture); //crashes here
assert(hr == S_OK);
where D3DDev_0001 is a ID3D11Device. I am able to create 3d and 2d textures, but making a 1d texture causes the program to crash. Can anyone explain why?
Upvotes: 1
Views: 234
Reputation: 3584
A USAGE_STAGING texture can't have any BindFlags since it can't be set on the graphics context for use as an SRV, UAV or RTV. Set BindFlags to 0 if you want a STAGING texture, or set the Usage to D3D11_USAGE_DEFAULT if you just want a 'normal' texture that can be bound to the context.
USAGE_STAGING resources are either for the CPU to fill in with data before being copied to a USAGE_DEFAULT resource, or, they're the destination for GPU copies to get data from the GPU back to the CPU.
The exact cause of this error would have been explained in a message printed by "D3D11's Debug Layer"; use it to find the cause of these errors in the future.
Upvotes: 3