stride3d/stride · error · InvalidOperationException
Invalid Width/Height/Depth/ArraySize for Image 1D
Error message
Invalid Width/Height/Depth/ArraySize for Image 1D
What it means
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.
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.
Example fix
// before
var desc = new ImageDescription { Dimension = TextureDimension.Texture1D, Width = 128 };
// after
var desc = new ImageDescription { Dimension = TextureDimension.Texture1D, Width = 128, Height = 1, Depth = 1, ArraySize = 1 }; Defensive patterns
Strategy: validation
Validate before calling
if (desc.Dimension == TextureDimension.Texture1D &&
(desc.Width <= 0 || desc.Height != 1 || desc.Depth != 1 || desc.ArraySize == 0))
throw new ArgumentException("Texture1D requires Width>0, Height=1, Depth=1, ArraySize>=1."); Type guard
null
Try / catch
try { img = Image.New(desc, ptr); }
catch (InvalidOperationException ex) when (ex.Message.Contains("for Image 1D"))
{
NormalizeDescription(desc); // force Height=1, Depth=1, ArraySize=1
img = Image.New(desc, ptr);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Reusing a 2D ImageDescription struct and only changing Dimension to Texture1D; default-initialized ImageDescription where Height/Depth/ArraySize are all 0.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Invalid Width/Height/Depth/ArraySize for Image 2D
- Unsupported DXGI Format
- Cannot specify custom stride with mipmaps
- TextureCube must have an arraysize = 6
- Invalid Width/Height/Depth/ArraySize for Image 3D
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/fb94ae03b9db2b69.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Foundation/Graphics/Image.cs:777
Register(ImageFileType.Jpg, StandardImageHelper.LoadFromMemory, StandardImageHelper.SaveJpgFromMemory);
Register(ImageFileType.Png, StandardImageHelper.LoadFromMemory, StandardImageHelper.SavePngFromMemory);
}
internal unsafe void Initialize(ImageDescription description, IntPtr dataPointer, int offset, GCHandle? handle, bool bufferIsDisposable, PitchFlags pitchFlags = PitchFlags.None, int rowStride = 0)
{
if (!description.Format.IsValid || description.Format.IsVideoFormat)
throw new InvalidOperationException("Unsupported DXGI Format");
if (rowStride > 0 && description.MipLevels != 1)
throw new InvalidOperationException("Cannot specify custom stride with mipmaps");
this.handle = handle;
switch (description.Dimension)
{
case TextureDimension.Texture1D:
if (description.Width <= 0 || description.Height != 1 || description.Depth != 1 || description.ArraySize == 0)
throw new InvalidOperationException("Invalid Width/Height/Depth/ArraySize for Image 1D");
// Check that miplevels are fine
description.MipLevels = CalculateMipLevels(description.Width, 1, description.MipLevels);
break;
case TextureDimension.Texture2D:
case TextureDimension.TextureCube:
if (description.Width <= 0 || description.Height <= 0 || description.Depth != 1 || description.ArraySize == 0)
throw new InvalidOperationException("Invalid Width/Height/Depth/ArraySize for Image 2D");
if (description.Dimension == TextureDimension.TextureCube)
{
if ((description.ArraySize % 6) != 0)
throw new InvalidOperationException("TextureCube must have an arraysize = 6");
}
// Check that miplevels are fine
description.MipLevels = CalculateMipLevels(description.Width, description.Height, description.MipLevels);View on GitHub (pinned to 96fad776d2)