Reputation: 1193
I'm trying to create and initialize a 2D texture array in the following way:
D3D11_TEXTURE2D_DESC desc{};
desc.ArraySize = 10; // there should be 10 textures
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
desc.Width = 256;
desc.Height = 1;
desc.MipLevels = 1;
desc.SampleDesc.Count = 1;
desc.CPUAccessFlags = 0;
D3D11_SUBRESOURCE_DATA subresourceData{};
subresourceData.pSysMem = data.data(); // data is a vector of 2560 elements of type XMVECTOR
subresourceData.SysMemPitch = 256 * sizeof(XMVECTOR);
subresourceData.SysMemSlicePitch = 256 * sizeof(XMVECTOR);
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_texture = nullptr;
m_device->CreateTexture2D(&desc, &subresourceData, &m_texture);
The problem is I'm getting an error Access violation reading location 0xFFFFFFFFFFFFFFFF
on calling CreateTexture2D
and m_texture
in NULL
. When I did not pass initialization data the problem did not occur:
m_device->CreateTexture2D(&desc, nullptr, &m_texture);
How can I initialize a texture array?
Upvotes: 1
Views: 290
Reputation: 1193
Problem solved: for texture array you have to pass an array of D3D11_SUBRESOURCE_DATA
in CreateTexture2D
function.
Upvotes: 1