{"record":{"id":"af0015ad92e97f3a","repo":"Unity-Technologies/UnityCsReference","slug":"src","errorCode":null,"errorMessage":"src","messagePattern":"src","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/MeshUtility.bindings.cs","lineNumber":35,"sourceCode":"    {\n        [FreeFunction] extern private static void OptimizeIndexBuffers([NotNull] Mesh mesh);\n        [FreeFunction] extern private static void OptimizeReorderVertexBuffer([NotNull] Mesh mesh);\n\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);","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/MeshUtility.bindings.cs#L17-L53","documentation":"Thrown by MeshUtility.SetPerTriangleUV2 when the src Mesh argument is null. The method writes per-triangle secondary UVs (UV2) into the mesh, so a null mesh is rejected before the native SetPerTriangleUV2NoCheck call.","triggerScenarios":"Calling SetPerTriangleUV2(mesh, triUV) with a mesh reference that is null — an unassigned Mesh field, a mesh destroyed mid-operation, or a null returned by a GetComponent/asset lookup.","commonSituations":"Editor mesh-processing tooling operating on a MeshFilter.sharedMesh that is null. A batch processor that yields null for some entries in a mesh list.","solutions":["Null-check the mesh before calling and skip or report null entries.","Ensure the Mesh field/asset is assigned and not destroyed before the call.","In batch loops, filter out null meshes before processing."],"exampleFix":"// before\nMeshUtility.SetPerTriangleUV2(mesh, triUV);\n\n// after\nif (mesh == null) throw new ArgumentNullException(nameof(mesh));\nMeshUtility.SetPerTriangleUV2(mesh, triUV);","handlingStrategy":"type-guard","validationCode":"if (mesh == null) throw new ArgumentNullException(nameof(mesh));","typeGuard":"static bool IsValidMesh(Mesh m) => m != null;","tryCatchPattern":"try { MeshUtility.SetPerTriangleUV2(mesh, triUV); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"src\") { Debug.LogError(\"Mesh is null.\"); }","preventionTips":["Null-check meshes before processing","Filter null entries in batch loops","Ensure MeshFilter.sharedMesh is assigned"],"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"}