{"record":{"id":"d4935f3669e2a831","repo":"Unity-Technologies/UnityCsReference","slug":"triuv","errorCode":null,"errorMessage":"triUV","messagePattern":"triUV","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/MeshUtility.bindings.cs","lineNumber":38,"sourceCode":"\n        public static void Optimize(Mesh mesh)\n        {\n            OptimizeIndexBuffers(mesh);\n            OptimizeReorderVertexBuffer(mesh);\n        }\n\n        extern public static void SetMeshCompression([NotNull] Mesh mesh, ModelImporterMeshCompression compression);\n        extern public static ModelImporterMeshCompression GetMeshCompression([NotNull] Mesh mesh);\n\n        [NativeName(\"SetPerTriangleUV2\")]\n        static extern bool SetPerTriangleUV2NoCheck(Mesh src, Vector2[] triUV);\n        public static bool SetPerTriangleUV2(Mesh src, Vector2[] triUV)\n        {\n            if (src == null)\n                throw new ArgumentNullException(\"src\");\n\n            if (triUV == null)\n                throw new ArgumentNullException(\"triUV\");\n\n            int triCount = InternalMeshUtil.CalcTriangleCount(src), uvCount  = triUV.Length;\n            if (uvCount != 3 * triCount)\n            {\n                Debug.LogError(\"mesh contains \" + triCount + \" triangles but \" + uvCount + \" uvs are provided\");\n                return false;\n            }\n            return SetPerTriangleUV2NoCheck(src, triUV);\n        }\n\n        extern internal static Vector2[] ComputeTextureBoundingHull(Texture texture, int vertexCount);\n\n        public static Mesh.MeshDataArray AcquireReadOnlyMeshData(Mesh mesh)\n        {\n            return new Mesh.MeshDataArray(mesh, false);\n        }\n\n        public static Mesh.MeshDataArray AcquireReadOnlyMeshData(Mesh[] meshes)","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/MeshUtility.bindings.cs#L20-L56","documentation":"Thrown by MeshUtility.SetPerTriangleUV2 when the triUV Vector2[] argument is null. The array must supply exactly 3 UVs per triangle, so null is rejected up front before triangle-count validation.","triggerScenarios":"Calling SetPerTriangleUV2 with a null uv array — e.g. a UV-generation step that returned null on failure, or an unallocated array passed by mistake.","commonSituations":"Procedural UV tooling where the generation function returns null instead of an empty/valid array. A code path that allocates the array conditionally and skips it.","solutions":["Ensure the triUV array is allocated with length equal to 3 * triangleCount before calling.","Treat a null from UV generation as an error and surface it earlier.","Null-check triUV before invoking SetPerTriangleUV2."],"exampleFix":"// before\nMeshUtility.SetPerTriangleUV2(mesh, triUV);\n\n// after\nvar triUV = new Vector2[3 * triCount];\n// ... fill triUV ...\nMeshUtility.SetPerTriangleUV2(mesh, triUV);","handlingStrategy":"validation","validationCode":"if (triUV == null) throw new ArgumentNullException(nameof(triUV));\nif (triUV.Length != 3 * InternalMeshUtil.CalcTriangleCount(mesh)) return false;","typeGuard":"static bool IsValidTriUV(Vector2[] uvs, Mesh m) => uvs != null && m != null && uvs.Length == 3 * InternalMeshUtil.CalcTriangleCount(m);","tryCatchPattern":"try { MeshUtility.SetPerTriangleUV2(mesh, triUV); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"triUV\") { Debug.LogError(\"UV array is null.\"); }","preventionTips":["Allocate triUV to 3 * triangleCount","Surface null from UV generation as an error","Null-check arrays before passing"],"tags":["unity","editor","mesh","argument-validation","uv"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}