{"record":{"id":"1d7122b818db41de","repo":"stride3d/stride","slug":"invalid-z-slice-index-image","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":260,"sourceCode":"        /// <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)\n                throw new ArgumentException(\"Invalid mipmap level\", nameof(mipmap));\n\n            if (arrayIndex > Description.ArraySize)\n                throw new ArgumentException(\"Invalid array slice index\", nameof(arrayIndex));\n\n            if (zIndex > Description.Depth)\n                throw new ArgumentException(\"Invalid Z slice index\", nameof(zIndex));\n\n            return GetPixelBufferUnsafe(arrayIndex, zIndex, mipmap);\n        }\n\n        /// <summary>\n        ///   Registers a loader / saver for a specified Image file type.\n        /// </summary>\n        /// <param name=\"type\">\n        ///   The file type. Use an integer and explicit casting to <see cref=\"ImageFileType\"/> to register other file formats.\n        /// </param>\n        /// <param name=\"loader\">\n        ///   A delegate that will be invoked to load an Image of the specified <paramref name=\"type\"/>.\n        ///   Specify <see langword=\"null\"/> to register no loading delegate for this type.\n        /// </param>\n        /// <param name=\"saver\">\n        ///   A delegate that will be invoked to save an Image of the specified <paramref name=\"type\"/>.\n        ///   Specify <see langword=\"null\"/> to register no saving delegate for this type.\n        /// </param>","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Foundation/Graphics/Image.cs#L242-L278","documentation":"GetPixelBuffer validates zIndex against Description.Depth for 3D (volume) textures. Requesting a Z slice beyond the image's depth is rejected with an ArgumentException. For 1D/2D images Depth is 1, so any zIndex above 0 throws.","triggerScenarios":"Calling image.GetPixelBuffer(arrayIndex, zIndex, mipmap) with zIndex > image.Description.Depth — e.g. accessing z=3 on a 2D image (Depth=1) or z >= texture depth on a volume texture.","commonSituations":"Using the same triple-index loop for 2D and 3D textures without honoring Description.Depth; passing world-space or texel z coordinates instead of a slice index; treating a 3D texture's depth as pixel height.","solutions":["Guard zIndex against image.Description.Depth before the call","Skip z iteration (use 0) for 1D/2D images where Depth is 1","Recreate the image with the required Depth if the slice should exist"],"exampleFix":"// before\nvar buf = image.GetPixelBuffer(0, z, 0); // any z\n// after\nif (z < image.Description.Depth)\n    var buf = image.GetPixelBuffer(0, z, 0);","handlingStrategy":"validation","validationCode":"if ((uint)zIndex >= image.Description.Depth) throw new ArgumentOutOfRangeException(nameof(zIndex));\nvar buf = image.GetPixelBuffer(0, zIndex, 0);","typeGuard":"bool IsValidZSlice(Image image, int z) => (uint)z < image.Description.Depth;","tryCatchPattern":"try { var buf = image.GetPixelBuffer(0, z, 0); }\ncatch (ArgumentException ex) when (ex.ParamName == \"zIndex\") { /* skip slice */ }","preventionTips":["Check Description.Dimension: only 3D images have z slices beyond 0","Keep z loops bounded by Description.Depth, not texture pixel height"],"tags":["csharp","stride","graphics","argument-validation"],"backgroundTag":"value-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"}