{"record":{"id":"6cf4b153f1be7760","repo":"stride3d/stride","slug":"invalid-width-height-depth-arraysize-for-image-3d","errorCode":null,"errorMessage":"Invalid Width/Height/Depth/ArraySize for Image 3D","messagePattern":"Invalid Width/Height/Depth/ArraySize for Image 3D","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Foundation/Graphics/Image.cs","lineNumber":800,"sourceCode":"\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;\n            }\n\n            // Calculate mipmaps\n            mipMapToZIndex = CalculateImageArray(description, pitchFlags, rowStride, out var pixelBufferCount, out totalSizeInBytes);\n            mipmapDescriptions = CalculateMipMapDescription(description);\n            zBufferCountPerArraySlice = mipMapToZIndex[^1];\n\n            // Allocate all pixel buffers\n            PixelBuffers = new PixelBuffer[pixelBufferCount];\n            pixelBufferArray = new PixelBufferArray(this);\n\n            // Setup all pointers\n            // only release buffer that is not pinned and is asked to be disposed.\n            this.bufferIsDisposable = !handle.HasValue && bufferIsDisposable;","sourceCodeStart":782,"sourceCodeEnd":818,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Foundation/Graphics/Image.cs#L782-L818","documentation":"For Texture3D images, Initialize requires Width > 0, Height > 0, Depth > 0, and ArraySize == 1. Volumetric textures must be truly 3-dimensional, and 3D images cannot be arrayed (ArraySize must be exactly 1).","triggerScenarios":"Creating an Image with Dimension = TextureDimension.Texture3D where any of Width/Height/Depth is <= 0, or where ArraySize was left > 1 or left at a non-1 value copied from a 2D array description.","commonSituations":"Loading volumetric data where the depth read from the file header is 0; cloning a 2D texture-array description and only changing Dimension to Texture3D (keeping ArraySize = 4); default-initialized descriptions with zeroed dimensions.","solutions":["Set ArraySize = 1 for Texture3D images.","Ensure Width, Height, and Depth are all > 0.","If you need an array of 2D slices, use Texture2D with ArraySize > 1 instead.","Validate the source file's depth field before constructing the description."],"exampleFix":"// before\nvar desc = new ImageDescription { Dimension = TextureDimension.Texture3D, Width = 64, Height = 64, Depth = 64, ArraySize = 4 };\n// after\nvar desc = new ImageDescription { Dimension = TextureDimension.Texture3D, Width = 64, Height = 64, Depth = 64, ArraySize = 1 };","handlingStrategy":"validation","validationCode":"if (desc.Dimension == TextureDimension.Texture3D &&\n    (desc.Width <= 0 || desc.Height <= 0 || desc.Depth <= 0 || desc.ArraySize != 1))\n    throw new ArgumentException(\"Texture3D requires Width/Height/Depth>0 and ArraySize=1.\");","typeGuard":"null","tryCatchPattern":"try { img = Image.New(desc, ptr); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"for Image 3D\"))\n{\n    desc.ArraySize = 1;\n    img = Image.New(desc, ptr);\n}","preventionTips":["Always reset ArraySize to 1 when converting a 2D-array description to 3D.","Validate volumetric file headers (depth > 0) before constructing descriptions.","Use a dedicated New3D factory to keep invariants in one place.","Unit-test each dimension's description builder."],"tags":["graphics","volume-texture","textures","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"}