{"record":{"id":"bc562aec8c91f530","repo":"stride3d/stride","slug":"invalid-texture-datas-first-dimension-must-be-equal-to-6","errorCode":null,"errorMessage":"Invalid texture datas. First dimension must be equal to 6","messagePattern":"Invalid texture datas\\. First dimension must be equal to 6","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/Texture.ExtensionsCube.cs","lineNumber":136,"sourceCode":"    ///   </para>\n    /// </param>\n    /// <param name=\"textureFlags\">\n    ///   A combination of flags determining what kind of Texture and how the is should behave\n    ///   (i.e. how it is bound, how can it be read / written, etc.).\n    ///   By default, it is <see cref=\"TextureFlags.ShaderResource\"/>.\n    /// </param>\n    /// <param name=\"usage\">\n    ///   A combination of flags determining how the Texture will be used during rendering.\n    ///   The default is <see cref=\"GraphicsResourceUsage.Immutable\"/>, meaning it will need read access by the GPU.\n    /// </param>\n    /// <returns>A new cube-map Texture.</returns>\n    /// <exception cref=\"ArgumentException\">\n    ///   The Texture data is invalid. The first dimension of <paramref name=\"textureData\"/> array must be equal to 6.\n    /// </exception>\n    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\n    {\n        if (textureData.Length != 6)\n            throw new ArgumentException(\"Invalid texture datas. First dimension must be equal to 6\", nameof(textureData));\n\n        var dataBoxes = new DataBox[6];\n\n        for (var i = 0; i < 6; i++)\n        {\n            fixed (void* texture = textureData[i])\n                dataBoxes[i] = GetDataBox(format, size, size, 1, textureData[0], (nint)texture);\n        }\n\n        var description = TextureDescription.NewCube(size, format, textureFlags, usage);\n\n        return new Texture(device).InitializeFrom(description, dataBoxes);\n    }\n\n    /// <summary>\n    ///   Creates a new cube-map composed of six two-dimensional (2D) <see cref=\"Texture\"/>s from a initial data.\n    /// </summary>\n    /// <param name=\"device\">The <see cref=\"GraphicsDevice\"/>.</param>","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/Texture.ExtensionsCube.cs#L118-L154","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nvar data = new byte[5][]; // one face missing\ntexture.NewCube(device, 256, PixelFormat.R8G8B8A8_UNorm, data);\n// after\nvar data = new byte[6][]; // +X, -X, +Y, -Y, +Z, -Z\nfor (int i = 0; i < 6; i++) data[i] = LoadFace(i);\ntexture.NewCube(device, 256, PixelFormat.R8G8B8A8_UNorm, data);","handlingStrategy":"validation","validationCode":"if (textureData is null || textureData.Length != 6)\n    throw new ArgumentException($\"Cube face data must have exactly 6 faces, got {textureData?.Length ?? 0}\", nameof(textureData));","typeGuard":"static bool IsCubeFaceData<T>(T[][]? d) => d is { Length: 6 };","tryCatchPattern":"try { tex = Texture.NewCube(device, size, fmt, faces); }\ncatch (ArgumentException ex)\n{\n    logger.LogError(ex, \"Cube data must have 6 faces, got {Count}\", faces.Length);\n    throw;\n}","preventionTips":["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."],"tags":["graphics","stride","cubemap","texture"],"backgroundTag":"shape-mismatch","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"}