stride3d/stride · error · ArgumentException
Invalid array slice index
Error message
Invalid array slice index
What it means
Thrown by Image.GetPixelBuffer for non-3D textures when arrayOrZSliceIndex exceeds Description.ArraySize. For 1D/2D textures the parameter selects an array slice and must be within the declared array size.
Solutions
- Loop with arraySlice < image.Description.ArraySize
- Verify the texture was created as a texture array / cubemap (ArraySize 6 for cubemaps) if face access is intended
- Recreate the image with a larger ArraySize if more slices are required
Example fix
// before
for (int slice = 0; slice <= image.Description.ArraySize; slice++)
var pb = image.GetPixelBuffer(slice, 0);
// after
for (int slice = 0; slice < image.Description.ArraySize; slice++)
var pb = image.GetPixelBuffer(slice, 0); Defensive patterns
Strategy: validation
Validate before calling
if (image.Description.Dimension != TextureDimension.Texture3D && (arraySlice < 0 || arraySlice >= image.Description.ArraySize))
throw new ArgumentOutOfRangeException(nameof(arraySlice), arraySlice, $"Array slice must be in [0,{image.Description.ArraySize})"); Type guard
bool IsValidArraySlice(Image image, int slice) =>
image.Description.Dimension != TextureDimension.Texture3D
? slice >= 0 && slice < image.Description.ArraySize
: slice >= 0 && slice < image.Description.Depth; Try / catch
try
{
var pb = image.GetPixelBuffer(arraySlice, mip);
}
catch (ArgumentException ex) when (ex.ParamName == "arrayOrZSliceIndex")
{
log.Warn($"Array slice {arraySlice} out of range (ArraySize={image.Description.ArraySize})");
return null;
} Prevention
- Remember ArraySize is a count, so valid indices go 0..ArraySize-1
- Check Description.Dimension and ArraySize before cube-map face access (cubemaps need ArraySize >= 6)
- Share slice iteration through one helper that reads the Description instead of duplicating loops
When it happens
Trigger: image.GetPixelBuffer(arraySlice, mip) on a 1D/2D texture where arraySlice >= Description.ArraySize, e.g. assuming ArraySize is a count starting at 1 or iterating a cube-map face index (6) on a texture with ArraySize 1.
Common situations: Off-by-one when ArraySize is a count vs. a max index; reading cube-map faces from a non-cubemap texture; sharing code between texture arrays and single textures without checking Description.ArraySize.
Related errors
- Invalid mipmap level
- Invalid z slice index
- The Graphics Resource is a Texture, but its dimension is…
- Value must be in between 1 and 32
- Cannot specify the format for more than 8 Render Targets.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/7bc08be39de06454.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Foundation/Graphics/Image.cs:235
/// <exception cref="ArgumentException">If arrayOrZSliceIndex or mipmap are out of range.</exception>
public PixelBuffer GetPixelBuffer(int arrayOrZSliceIndex, int mipmap)
{
// Check for parameters, as it is easy to mess up things...
if (mipmap > Description.MipLevels)
throw new ArgumentException("Invalid mipmap level", nameof(mipmap));
if (Description.Dimension == TextureDimension.Texture3D)
{
if (arrayOrZSliceIndex > Description.Depth)
throw new ArgumentException("Invalid z slice index", nameof(arrayOrZSliceIndex));
// For 3D textures
return GetPixelBufferUnsafe(0, arrayOrZSliceIndex, mipmap);
}
if (arrayOrZSliceIndex > Description.ArraySize)
{
throw new ArgumentException("Invalid array slice index", nameof(arrayOrZSliceIndex));
}
// For 1D, 2D textures
return GetPixelBufferUnsafe(arrayOrZSliceIndex, 0, mipmap);
}
/// <summary>
/// Gets the pixel buffer for the specified array/z slice and mipmap level.
/// </summary>
/// <param name="arrayIndex">Index into the texture array. Must be set to 0 for 3D images.</param>
/// <param name="zIndex">Z index for 3D image. Must be set to 0 for all 1D/2D images.</param>
/// <param name="mipmap">The mipmap.</param>
/// <returns>A <see cref="Graphics.PixelBuffer"/>.</returns>
/// <exception cref="ArgumentException">If arrayIndex, zIndex or mipmap are out of range.</exception>
public PixelBuffer GetPixelBuffer(int arrayIndex, int zIndex, int mipmap)
{
// Check for parameters, as it is easy to mess up things...
if (mipmap > Description.MipLevels)View on GitHub (pinned to 96fad776d2)