{"record":{"id":"817022005ca90896","repo":"stride3d/stride","slug":"invalid-mipmap-level","errorCode":null,"errorMessage":"Invalid mipmap level","messagePattern":"Invalid mipmap level","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Foundation/Graphics/Image.cs","lineNumber":222,"sourceCode":"        /// <param name=\"mipmap\">The mipmap.</param>\n        /// <returns>A description of a particular mipmap for this texture.</returns>\n        public MipMapDescription GetMipMapDescription(int mipmap)\n        {\n            return mipmapDescriptions[mipmap];\n        }\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        }","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Foundation/Graphics/Image.cs#L204-L240","documentation":"Thrown by Image.GetPixelBuffer(arrayOrZSliceIndex, mipmap) when the requested mipmap level is greater than the texture's Description.MipLevels. Mipmap indices are zero-based and must stay below the declared mip count, so an out-of-range index indicates a caller bug or stale texture description.","triggerScenarios":"Calling image.GetPixelBuffer(0, mipmap) where mipmap >= Description.MipLevels, e.g. iterating mips with '<=' instead of '<', or reading mips from a reloaded image whose Description.MipLevels is smaller than expected.","commonSituations":"Looping over a hardcoded mip count (e.g. full chain of 12) while the image was loaded with a reduced chain; mismatch after resizing a texture so fewer mips are generated; code assuming mip levels from a different image instance.","solutions":["Clamp or loop with mip < image.Description.MipLevels","Compute the mip count from the texture dimensions (e.g. floor(log2(maxDim)) + 1) instead of hardcoding","If more mips are needed, recreate the image with a Description specifying the higher MipLevels"],"exampleFix":"// before\nfor (int mip = 0; mip <= image.Description.MipLevels; mip++)\n    var pb = image.GetPixelBuffer(0, mip);\n// after\nfor (int mip = 0; mip < image.Description.MipLevels; mip++)\n    var pb = image.GetPixelBuffer(0, mip);","handlingStrategy":"validation","validationCode":"if (mip < 0 || mip >= image.Description.MipLevels)\n    throw new ArgumentOutOfRangeException(nameof(mip), mip, $\"Mip must be in [0,{image.Description.MipLevels})\");","typeGuard":"bool IsValidMip(Image image, int mip) => mip >= 0 && mip < image.Description.MipLevels;","tryCatchPattern":"try\n{\n    var pb = image.GetPixelBuffer(slice, mip);\n}\ncatch (ArgumentException ex) when (ex.ParamName == \"mipmap\")\n{\n    log.Warn($\"Mip {mip} unavailable (MipLevels={image.Description.MipLevels})\");\n    return null;\n}","preventionTips":["Always derive mip loops from image.Description.MipLevels with strict '<'","Never hardcode mip chain lengths (e.g. 12 for 4K); compute from dimensions when creating textures","Re-check Description after any image reload or resize"],"tags":["graphics","mipmap","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"}