egametang/ET · error · Exception

Invalid vector, expected 3 coordinates, found {v.Length - 1}

Error message

Invalid vector, expected 3 coordinates, found {v.Length - 1}

What it means

Thrown by ObjImporter.ReadVector3f when a vertex/normal line, after space-splitting, yields fewer than 4 tokens (the prefix token + 3 coordinates). The importer expects exactly three float coordinates; fewer means the OBJ line is malformed or truncated.

Source

Thrown at Packages/cn.etetet.recast/Scripts/Core/Share/Recast/ObjImporter.cs:86

        private static void ReadVertex(string line, ObjImporterContext context)
        {
            if (line.StartsWith("v "))
            {
                float[] vert = ReadVector3f(line);
                foreach (float vp in vert)
                {
                    context.vertexPositions.Add(vp);
                }
            }
        }

        private static float[] ReadVector3f(string line)
        {
            string[] v = line.Split(' ', StringSplitOptions.RemoveEmptyEntries);
            if (v.Length < 4)
            {
                throw new Exception("Invalid vector, expected 3 coordinates, found " + (v.Length - 1));
            }

            // fix - https://github.com/ikpil/DotRecast/issues/7
            return new float[]
            {
                float.Parse(v[1], CultureInfo.InvariantCulture), 
                float.Parse(v[2], CultureInfo.InvariantCulture), 
                float.Parse(v[3], CultureInfo.InvariantCulture)
            };
        }

        private static void ReadFace(string line, ObjImporterContext context)
        {
            string[] v = line.Split(' ', StringSplitOptions.RemoveEmptyEntries);
            if (v.Length < 4)
            {
                throw new Exception("Invalid number of face vertices: 3 coordinates expected, found " + v.Length);
            }

View on GitHub (pinned to 5cab01f7a8)

Solutions

  1. Open the OBJ and locate the offending 'v'/'vn' line; supply the missing coordinate.
  2. Re-export the mesh with a known-good exporter (e.g., Blender OBJ) that emits three axes.
  3. Pre-scan the OBJ for vertex lines lacking three numeric tokens and report line numbers.

Example fix

// before: line in file
v 1.0 2.0

// after
v 1.0 2.0 0.0
Defensive patterns

Strategy: validation

Validate before calling

// Pre-scan vertex lines for < 3 numeric coordinates.
foreach (var line in lines)
    if (line.StartsWith("v ") || line.StartsWith("vn "))
    {
        var toks = line.Split(' ', StringSplitOptions.RemoveEmptyEntries);
        if (toks.Length < 4) throw new InvalidDataException($"Bad OBJ line: {line}");
    }

Type guard

static bool IsValidVertexLine(string line)
{ var t = line.Split(' ', StringSplitOptions.RemoveEmptyEntries); return t.Length >= 4; }

Try / catch

try { ObjImporter.Load(chunk); }
catch (Exception e) when (e.Message.Contains("Invalid vector"))
{ /* locate/fix the offending 'v' line in the source */ }

Prevention

When it happens

Trigger: An OBJ 'v' or 'vn' line with only one or two coordinates (e.g., 'v 1.0 2.0'); a line accidentally containing a non-space delimiter; extra empty tokens stripped by RemoveEmptyEntries leaving too few.

Common situations: Hand-edited or exporter-bugged OBJ files; 2D/planar exporters omitting one axis; whitespace corruption.

Related errors


AI-assisted analysis of egametang/ET@5cab01f7a8 (2026-08-13). Data as JSON: /api/errors/24aefd4dee646013. Report an issue: GitHub.