stride3d/stride · error · ArgumentException
Invalid texture datas. First dimension must be equal to 6
Error message
Invalid texture datas. First dimension must be equal to 6
What it means
Texture.ExtensionsCube.NewCube builds a cube map from six face data arrays; a TextureCube has exactly 6 faces (+X, -X, +Y, -Y, +Z, -Z). The library throws ArgumentException when textureData.Length != 6, since the first array dimension must supply one element per cube face.
Solutions
- Ensure the outer array contains exactly 6 sub-arrays, one per face in cube-face order.
- If passing mips, restructure so the outer dimension is faces; mips belong inside each face's data.
- Log textureData.Length before the call to catch data-generation bugs.
Example fix
// before var data = new byte[5][]; // one face missing texture.NewCube(device, 256, PixelFormat.R8G8B8A8_UNorm, data); // after var data = new byte[6][]; // +X, -X, +Y, -Y, +Z, -Z for (int i = 0; i < 6; i++) data[i] = LoadFace(i); texture.NewCube(device, 256, PixelFormat.R8G8B8A8_UNorm, data);
Defensive patterns
Strategy: validation
Validate before calling
if (textureData is null || textureData.Length != 6)
throw new ArgumentException($"Cube face data must have exactly 6 faces, got {textureData?.Length ?? 0}", nameof(textureData)); Type guard
static bool IsCubeFaceData<T>(T[][]? d) => d is { Length: 6 }; Try / catch
try { tex = Texture.NewCube(device, size, fmt, faces); }
catch (ArgumentException ex)
{
logger.LogError(ex, "Cube data must have 6 faces, got {Count}", faces.Length);
throw;
} Prevention
- Use a fixed face order (+X,-X,+Y,-Y,+Z,-Z) when filling face arrays.
- Assert face count in unit tests for your loader.
- Never reuse 2D mip arrays as cube face arrays.
When it happens
Trigger: Calling Texture.NewCube(device, size, format, T[][] textureData) with an array whose outer length is 0, 1, or more than 6 (e.g. passing all mip levels flattened into the outer dimension).
Common situations: Hand-assembling cube face data and miscounting faces; passing a 2D array where rows are mips instead of faces; deserializing skybox data with a wrong outer dimension.
Related errors
- TextureCube must have an arraysize = 6
- Custom strides is not supported with packed PixelFormats
- The Texture must be a Render Target
- The camera [ ] is disabled and can't be attached
- The camera [ ] is already attached
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/bc562aec8c91f530.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Graphics/Texture.ExtensionsCube.cs:136
/// </para>
/// </param>
/// <param name="textureFlags">
/// A combination of flags determining what kind of Texture and how the is should behave
/// (i.e. how it is bound, how can it be read / written, etc.).
/// By default, it is <see cref="TextureFlags.ShaderResource"/>.
/// </param>
/// <param name="usage">
/// A combination of flags determining how the Texture will be used during rendering.
/// The default is <see cref="GraphicsResourceUsage.Immutable"/>, meaning it will need read access by the GPU.
/// </param>
/// <returns>A new cube-map Texture.</returns>
/// <exception cref="ArgumentException">
/// The Texture data is invalid. The first dimension of <paramref name="textureData"/> array must be equal to 6.
/// </exception>
public static unsafe Texture NewCube<T>(GraphicsDevice device, int size, PixelFormat format, T[][] textureData, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable) where T : unmanaged
{
if (textureData.Length != 6)
throw new ArgumentException("Invalid texture datas. First dimension must be equal to 6", nameof(textureData));
var dataBoxes = new DataBox[6];
for (var i = 0; i < 6; i++)
{
fixed (void* texture = textureData[i])
dataBoxes[i] = GetDataBox(format, size, size, 1, textureData[0], (nint)texture);
}
var description = TextureDescription.NewCube(size, format, textureFlags, usage);
return new Texture(device).InitializeFrom(description, dataBoxes);
}
/// <summary>
/// Creates a new cube-map composed of six two-dimensional (2D) <see cref="Texture"/>s from a initial data.
/// </summary>
/// <param name="device">The <see cref="GraphicsDevice"/>.</param>View on GitHub (pinned to 96fad776d2)