stride3d/stride · error · ArgumentException
The length of the source data buffer
Error message
The length of the source data buffer ({fromDataSizeInBytes} bytes) is not compatible with the expected largestSize of at least {sizeOfTextureData} bytes : Width * Height * Depth * sizeof(Format) largestSize in bytes What it means
Thrown when the source buffer supplied to a Texture copy-from method is smaller than the required texture data size (textureDepthStride * depth). The library must read width*height*depth worth of pixels, so an undersized TData[] cannot satisfy the copy. Raised as ArgumentException.
Solutions
- Allocate the buffer with at least slicePitch * depth bytes (use Image.ComputePitch to get exact pitches).
- Check fromData.Length * sizeof(T) >= expected size before calling, and log both values.
- If using a smaller T (e.g. byte), increase Length proportionally to the format's bytes-per-pixel.
Example fix
// before byte[] data = new byte[w * h]; // too small for 32bpp texture.SetData(cmd, data); // after Image.ComputePitch(texture.Format, w, h, out var rowPitch, out var slicePitch, out _, out _); byte[] data = new byte[slicePitch * depth]; texture.SetData(cmd, data);
Defensive patterns
Strategy: validation
Validate before calling
Image.ComputePitch(texture.Format, width, height, out _, out var slicePitch, out _, out _);
int required = slicePitch * depth;
if (fromData.Length * sizeof(TData) < required)
throw new InvalidOperationException($"Buffer too small: {fromData.Length * sizeof(TData)} < {required}"); Try / catch
try { texture.SetData(cmd, data); }
catch (ArgumentException e) when (e.Message.Contains("not compatible with the expected")) { log.Error("Source buffer smaller than texture data", e); } Prevention
- Size buffers with Image.ComputePitch, never with naive width*height*bpp.
- Match sizeof(T) to the format's bytes per pixel.
- Validate loaded asset file sizes before uploading.
When it happens
Trigger: Calling a Texture method with a fromData array whose byte size (Length * sizeof(TData)) is less than sizeOfTextureData computed from the region/mip dimensions and format size.
Common situations: Using a byte[] for a 4-byte-per-pixel format without scaling length; forgetting rowPitch/slicePitch padding; reading a truncated file into the buffer; half-float vs float mismatches.
Understand the failure class
Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.
Related errors
- Invalid Texture data length
- Data chunk is not loaded.
- Expecting a Texture supporting UAV
- Expecting texture supporting UAV
- Invalid texture datas. First dimension must be equal to 6
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/1feab54006278387.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Graphics/Texture.cs:1488
width = regionToCheck.Width;
height = regionToCheck.Height;
depth = regionToCheck.Depth;
}
var sizePerElement = Format.SizeInBytes;
// Compute actual pitch
Image.ComputePitch(Format, width, height, out var rowStride, out var textureDepthStride, out width, out height);
// Size Of actual texture data
int sizeOfTextureData = textureDepthStride * depth;
int fromDataSizeInBytes = fromData.Length * sizeof(TData);
// Check largestSize validity of data to copy from
if (fromDataSizeInBytes < sizeOfTextureData)
throw new ArgumentException($"The length of the source data buffer ({fromDataSizeInBytes} bytes) is not compatible with the expected largestSize " +
$"of at least {sizeOfTextureData} bytes : Width * Height * Depth * sizeof(Format) largestSize in bytes");
int subResourceIndex = GetSubResourceIndex(arrayIndex, mipLevel);
fixed (void* ptrFromData = fromData)
{
// If the Texture is declared as Default usage, we use UpdateSubresource that supports sub-Resource region
if (Usage == GraphicsResourceUsage.Default)
{
if (region is ResourceRegion validRegion)
{
commandList.UpdateSubResource(resource: this, subResourceIndex, new DataBox((nint) ptrFromData, rowStride, textureDepthStride), validRegion);
}
else
{
commandList.UpdateSubResource(resource: this, subResourceIndex, new DataBox((nint) ptrFromData, rowStride, textureDepthStride));
}
}View on GitHub (pinned to 96fad776d2)