{"record":{"id":"7bc08be39de06454","repo":"stride3d/stride","slug":"invalid-array-slice-index","errorCode":null,"errorMessage":"Invalid array slice index","messagePattern":"Invalid array slice index","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Foundation/Graphics/Image.cs","lineNumber":235,"sourceCode":"        /// <exception cref=\"ArgumentException\">If arrayOrZSliceIndex or mipmap are out of range.</exception>\n        public PixelBuffer GetPixelBuffer(int arrayOrZSliceIndex, int mipmap)\n        {\n            // Check for parameters, as it is easy to mess up things...\n            if (mipmap > Description.MipLevels)\n                throw new ArgumentException(\"Invalid mipmap level\", nameof(mipmap));\n\n            if (Description.Dimension == TextureDimension.Texture3D)\n            {\n                if (arrayOrZSliceIndex > Description.Depth)\n                    throw new ArgumentException(\"Invalid z slice index\", nameof(arrayOrZSliceIndex));\n\n                // For 3D textures\n                return GetPixelBufferUnsafe(0, arrayOrZSliceIndex, mipmap);\n            }\n\n            if (arrayOrZSliceIndex > Description.ArraySize)\n            {\n                throw new ArgumentException(\"Invalid array slice index\", nameof(arrayOrZSliceIndex));\n            }\n\n            // For 1D, 2D textures\n            return GetPixelBufferUnsafe(arrayOrZSliceIndex, 0, mipmap);\n        }\n\n        /// <summary>\n        /// Gets the pixel buffer for the specified array/z slice and mipmap level.\n        /// </summary>\n        /// <param name=\"arrayIndex\">Index into the texture array. Must be set to 0 for 3D images.</param>\n        /// <param name=\"zIndex\">Z index for 3D image. Must be set to 0 for all 1D/2D images.</param>\n        /// <param name=\"mipmap\">The mipmap.</param>\n        /// <returns>A <see cref=\"Graphics.PixelBuffer\"/>.</returns>\n        /// <exception cref=\"ArgumentException\">If arrayIndex, zIndex or mipmap are out of range.</exception>\n        public PixelBuffer GetPixelBuffer(int arrayIndex, int zIndex, int mipmap)\n        {\n            // Check for parameters, as it is easy to mess up things...\n            if (mipmap > Description.MipLevels)","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Foundation/Graphics/Image.cs#L217-L253","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nfor (int slice = 0; slice <= image.Description.ArraySize; slice++)\n    var pb = image.GetPixelBuffer(slice, 0);\n// after\nfor (int slice = 0; slice < image.Description.ArraySize; slice++)\n    var pb = image.GetPixelBuffer(slice, 0);","handlingStrategy":"validation","validationCode":"if (image.Description.Dimension != TextureDimension.Texture3D && (arraySlice < 0 || arraySlice >= image.Description.ArraySize))\n    throw new ArgumentOutOfRangeException(nameof(arraySlice), arraySlice, $\"Array slice must be in [0,{image.Description.ArraySize})\");","typeGuard":"bool IsValidArraySlice(Image image, int slice) =>\n    image.Description.Dimension != TextureDimension.Texture3D\n        ? slice >= 0 && slice < image.Description.ArraySize\n        : slice >= 0 && slice < image.Description.Depth;","tryCatchPattern":"try\n{\n    var pb = image.GetPixelBuffer(arraySlice, mip);\n}\ncatch (ArgumentException ex) when (ex.ParamName == \"arrayOrZSliceIndex\")\n{\n    log.Warn($\"Array slice {arraySlice} out of range (ArraySize={image.Description.ArraySize})\");\n    return null;\n}","preventionTips":["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"],"tags":["graphics","texture-array","argument-out-of-range"],"backgroundTag":"argument-out-of-range","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}