{"record":{"id":"6865855501a09558","repo":"stride3d/stride","slug":"invalid-z-slice-index","errorCode":null,"errorMessage":"Invalid z slice index","messagePattern":"Invalid z slice index","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Foundation/Graphics/Image.cs","lineNumber":227,"sourceCode":"        }\n\n        /// <summary>\n        /// Gets the pixel buffer for the specified array/z slice and mipmap level.\n        /// </summary>\n        /// <param name=\"arrayOrZSliceIndex\">For 3D image, the parameter is the Z slice, otherwise it is an index into the texture array.</param>\n        /// <param name=\"mipmap\">The mipmap.</param>\n        /// <returns>A <see cref=\"Graphics.PixelBuffer\"/>.</returns>\n        /// <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>","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Foundation/Graphics/Image.cs#L209-L245","documentation":"Thrown by Image.GetPixelBuffer when the texture is 3D and arrayOrZSliceIndex exceeds Description.Depth. For Texture3D textures the second parameter indexes a Z slice and must be within the texture's depth at that mip level.","triggerScenarios":"image.GetPixelBuffer(zSlice, mip) on a Texture3D image where zSlice >= Description.Depth, e.g. iterating slices with '<=' or using an ArraySize-style loop on a 3D texture.","commonSituations":"Treating a 3D (volume) texture like a 2D texture array and looping over ArraySize instead of Depth; using slice counts from a source volume asset larger than the allocated texture.","solutions":["Loop with zSlice < image.Description.Depth for 3D textures","Branch on Description.Dimension to pick the right range (Depth for 3D, ArraySize otherwise)","Recreate the image with a larger Depth if more slices are genuinely needed"],"exampleFix":"// before\nfor (int z = 0; z <= image.Description.Depth; z++)\n    var pb = image.GetPixelBuffer(z, mip);\n// after\nfor (int z = 0; z < image.Description.Depth; z++)\n    var pb = image.GetPixelBuffer(z, mip);","handlingStrategy":"validation","validationCode":"if (image.Description.Dimension == TextureDimension.Texture3D && (zSlice < 0 || zSlice >= image.Description.Depth))\n    throw new ArgumentOutOfRangeException(nameof(zSlice), zSlice, $\"Z slice must be in [0,{image.Description.Depth})\");","typeGuard":"bool IsValidZSlice(Image image, int slice) =>\n    image.Description.Dimension == TextureDimension.Texture3D\n        ? slice >= 0 && slice < image.Description.Depth\n        : slice >= 0 && slice < image.Description.ArraySize;","tryCatchPattern":"try\n{\n    var pb = image.GetPixelBuffer(zSlice, mip);\n}\ncatch (ArgumentException ex) when (ex.ParamName == \"arrayOrZSliceIndex\")\n{\n    log.Warn($\"Z slice {zSlice} out of range for 3D texture (Depth={image.Description.Depth})\");\n    return null;\n}","preventionTips":["Branch on Description.Dimension before iterating slices: Depth for 3D, ArraySize otherwise","Use strict '<' comparisons when looping slices","Note that Depth shrinks per mip level for 3D textures; take that into account when accessing deeper mips"],"tags":["graphics","texture3d","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"}