{"record":{"id":"fb94ae03b9db2b69","repo":"stride3d/stride","slug":"invalid-width-height-depth-arraysize-for-image-1d","errorCode":null,"errorMessage":"Invalid Width/Height/Depth/ArraySize for Image 1D","messagePattern":"Invalid Width/Height/Depth/ArraySize for Image 1D","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Foundation/Graphics/Image.cs","lineNumber":777,"sourceCode":"            Register(ImageFileType.Jpg, StandardImageHelper.LoadFromMemory, StandardImageHelper.SaveJpgFromMemory);\n            Register(ImageFileType.Png, StandardImageHelper.LoadFromMemory, StandardImageHelper.SavePngFromMemory);\n        }\n\n        internal unsafe void Initialize(ImageDescription description, IntPtr dataPointer, int offset, GCHandle? handle, bool bufferIsDisposable, PitchFlags pitchFlags = PitchFlags.None, int rowStride = 0)\n        {\n            if (!description.Format.IsValid || description.Format.IsVideoFormat)\n                throw new InvalidOperationException(\"Unsupported DXGI Format\");\n\n            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);","sourceCodeStart":759,"sourceCodeEnd":795,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Foundation/Graphics/Image.cs#L759-L795","documentation":"For Texture1D images, Initialize requires Width > 0, Height == 1, Depth == 1, and ArraySize > 0. A 1D image is exactly one pixel tall and one deep; any other dimension combination is inconsistent with the declared TextureDimension and is rejected.","triggerScenarios":"Building an ImageDescription with Dimension = TextureDimension.Texture1D but leaving Height/Depth at a non-1 default (e.g. 0), setting Width <= 0, or leaving ArraySize at 0.","commonSituations":"Reusing a 2D ImageDescription struct and only changing Dimension to Texture1D; default-initialized ImageDescription where Height/Depth/ArraySize are all 0.","solutions":["Set Height = 1 and Depth = 1 explicitly for Texture1D descriptions.","Set ArraySize to at least 1 (1 for a plain 1D texture).","Ensure Width > 0.","If you actually need a 2D image, keep Height > 1 and use TextureDimension.Texture2D."],"exampleFix":"// before\nvar desc = new ImageDescription { Dimension = TextureDimension.Texture1D, Width = 128 };\n// after\nvar desc = new ImageDescription { Dimension = TextureDimension.Texture1D, Width = 128, Height = 1, Depth = 1, ArraySize = 1 };","handlingStrategy":"validation","validationCode":"if (desc.Dimension == TextureDimension.Texture1D &&\n    (desc.Width <= 0 || desc.Height != 1 || desc.Depth != 1 || desc.ArraySize == 0))\n    throw new ArgumentException(\"Texture1D requires Width>0, Height=1, Depth=1, ArraySize>=1.\");","typeGuard":"null","tryCatchPattern":"try { img = Image.New(desc, ptr); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"for Image 1D\"))\n{\n    NormalizeDescription(desc); // force Height=1, Depth=1, ArraySize=1\n    img = Image.New(desc, ptr);\n}","preventionTips":["Never reuse a 2D description struct for 1D images; use a factory per dimension.","Always initialize all ImageDescription fields, not just the ones you think matter.","Add a central Validate(ImageDescription) helper used before every Image.New call.","Log the full description on failure so the offending field is obvious."],"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"}