Crash when creating RenderTargetViews for Cubemap

I want to create a cubemap and I want to render to it and later sample from it for reflections. However, It crashes when I try to create the faces for the cubemap. Here is my code:

RenderTargetCube::RenderTargetCube(ID3D11Device* device, int resolution, DXGI_FORMAT format) {      D3D11_TEXTURE2D_DESC desc = {};     desc.Width = resolution;     desc.Height = resolution;     desc.MipLevels = 1;     desc.ArraySize = 6;     desc.Format = format;     desc.SampleDesc.Count = 1;     desc.SampleDesc.Quality = 0;     desc.Usage = D3D11_USAGE_DEFAULT;     desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;     desc.CPUAccessFlags = 0;     desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;      HRESULT res = device->CreateTexture2D(&desc, NULL, &Texture);     throwIfFailed(res);      D3D11_RENDER_TARGET_VIEW_DESC viewDesc = {};     viewDesc.Format = desc.Format;     viewDesc.Texture2DArray.ArraySize = 6;     viewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;     for (int i = 0; i < 6; i++) {         viewDesc.Texture2DArray.FirstArraySlice = D3D11CalcSubresource(0, i, 1);         res = device->CreateRenderTargetView(Texture.Get(), &viewDesc, RenderTargetView[i].GetAddressOf()); // crash here         throwIfFailed(res);      } 

and here is the message I receive:

D3D11 ERROR: ID3D11Device::CreateRenderTargetView: The Dimensions of the View are invalid due to at least one of the following conditions. MipSlice (value = 0) must be between 0 and MipLevels-1 of the Texture Resource, 0, inclusively. FirstArraySlice (value = 1) must be between 0 and ArraySize-1 of the Texture Resource, 5, inclusively. With the current FirstArraySlice, ArraySize (value = 6) must be between 1 and 5, inclusively, or -1 to default to all slices from FirstArraySlice, in order that the View fit on the Texture. [ STATE_CREATION ERROR #137: CREATERENDERTARGETVIEW_INVALIDDIMENSIONS]

I dont quite understand the error message, especially the last part about ArraySize, why does it want it to be between 1 and 5 and not 0 to 5?

Map an equirectangular square slice inside cubemap

I’m trying to map a square slice of an equirectangular image inside a cubemap with 6 faces, without distortion.

The point is that I’m dealing with huge array sizes if I try to project the whole equirectangular texture (because the circumference is Earth-like), so I’m cutting it into pieces on demand, with a higher detail.

I need to convert/project this square image (512*512px) which is covering 0.08° of the 360*180 degrees that the equirectangular image provides. The total circumference is 44053660mts. and the offset is 34.5° Lat and 56.8 ° Lon. (These values would change, but not the circumference)

Can you help me to find a way to project that image onto a cubemap?

I already have an algorithm to make a cubemap from the full equirectangular image but can’t find a way to do the same with just a squared portion of it.

Thanks!