{"record":{"id":"27120de4573bbf59","repo":"stride3d/stride","slug":"invalid-width-height-depth-arraysize-for-image-2d","errorCode":null,"errorMessage":"Invalid Width/Height/Depth/ArraySize for Image 2D","messagePattern":"Invalid Width/Height/Depth/ArraySize for Image 2D","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Foundation/Graphics/Image.cs","lineNumber":786,"sourceCode":"            if (rowStride > 0 && description.MipLevels != 1)\n                throw new InvalidOperationException(\"Cannot specify custom stride with mipmaps\");\n\n            this.handle = handle;\n\n            switch (description.Dimension)\n            {\n                case TextureDimension.Texture1D:\n                    if (description.Width <= 0 || description.Height != 1 || description.Depth != 1 || description.ArraySize == 0)\n                        throw new InvalidOperationException(\"Invalid Width/Height/Depth/ArraySize for Image 1D\");\n\n                    // Check that miplevels are fine\n                    description.MipLevels = CalculateMipLevels(description.Width, 1, description.MipLevels);\n                    break;\n\n                case TextureDimension.Texture2D:\n                case TextureDimension.TextureCube:\n                    if (description.Width <= 0 || description.Height <= 0 || description.Depth != 1 || description.ArraySize == 0)\n                        throw new InvalidOperationException(\"Invalid Width/Height/Depth/ArraySize for Image 2D\");\n\n                    if (description.Dimension == TextureDimension.TextureCube)\n                    {\n                        if ((description.ArraySize % 6) != 0)\n                            throw new InvalidOperationException(\"TextureCube must have an arraysize = 6\");\n                    }\n\n                    // Check that miplevels are fine\n                    description.MipLevels = CalculateMipLevels(description.Width, description.Height, description.MipLevels);\n                    break;\n\n                case TextureDimension.Texture3D:\n                    if (description.Width <= 0 || description.Height <= 0 || description.Depth <= 0 || description.ArraySize != 1)\n                        throw new InvalidOperationException(\"Invalid Width/Height/Depth/ArraySize for Image 3D\");\n\n                    // Check that miplevels are fine\n                    description.MipLevels = CalculateMipLevels(description.Width, description.Height, description.Depth, description.MipLevels);\n                    break;","sourceCodeStart":768,"sourceCodeEnd":804,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Foundation/Graphics/Image.cs#L768-L804","documentation":"For Texture2D and TextureCube images, Initialize requires Width > 0, Height > 0, Depth == 1, and ArraySize > 0. 2D images have no volumetric depth and must contain at least one array slice; anything else contradicts the declared dimension.","triggerScenarios":"Creating an image with Dimension = TextureDimension.Texture2D (or TextureCube) where Depth != 1, ArraySize == 0, or Width/Height <= 0 — e.g. a default-initialized ImageDescription or a description zeroed by a failed load.","commonSituations":"Passing a 3D description with Depth > 1 while leaving Dimension as Texture2D; forgetting to set ArraySize when hand-building descriptions; image dimensions taken from a file header that failed to parse (width/height 0).","solutions":["Set Depth = 1 for Texture2D/TextureCube descriptions.","Set ArraySize >= 1 (6 * faceCount for cubes).","Ensure Width and Height are both positive.","Use TextureDimension.Texture3D if you genuinely need Depth > 1."],"exampleFix":"// before\nvar desc = new ImageDescription { Dimension = TextureDimension.Texture2D, Width = w, Height = h, Depth = 4, ArraySize = 0 };\n// after\nvar desc = new ImageDescription { Dimension = TextureDimension.Texture2D, Width = w, Height = h, Depth = 1, ArraySize = 1 };","handlingStrategy":"validation","validationCode":"bool is2D = desc.Dimension is TextureDimension.Texture2D or TextureDimension.TextureCube;\nif (is2D && (desc.Width <= 0 || desc.Height <= 0 || desc.Depth != 1 || desc.ArraySize == 0))\n    throw new ArgumentException(\"Texture2D/Cube requires Width>0, Height>0, Depth=1, ArraySize>=1.\");","typeGuard":"null","tryCatchPattern":"try { img = Image.New2D(width, height, mipCount, format, isArray, arraySize); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"for Image 2D\"))\n{\n    logger.LogError(\"Invalid 2D image desc w={W} h={H} d={D} arr={A}\", width, height, depth, arraySize);\n    throw;\n}","preventionTips":["Check file headers for zero width/height before building descriptions.","Set Depth = 1 explicitly for all 2D/cube descriptions.","Use New2D/NewCube helpers instead of raw descriptions where possible.","Clamp or reject decoded dimensions <= 0 at the loader boundary."],"tags":["graphics","textures","validation","stride"],"backgroundTag":"invalid-argument-value","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"}