{"record":{"id":"a99ddfe5bf6df271","repo":"Unity-Technologies/UnityCsReference","slug":"mesh-array-is-null","errorCode":null,"errorMessage":"Mesh array is null","messagePattern":"Mesh array is null","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/MeshUtility.bindings.cs","lineNumber":59,"sourceCode":"            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)\n        {\n            if (meshes == null)\n                throw new ArgumentNullException(nameof(meshes), \"Mesh array is null\");\n            return new Mesh.MeshDataArray(meshes, meshes.Length, false);\n        }\n\n        public static Mesh.MeshDataArray AcquireReadOnlyMeshData(List<Mesh> meshes)\n        {\n            if (meshes == null)\n                throw new ArgumentNullException(nameof(meshes), \"Mesh list is null\");\n            return new Mesh.MeshDataArray(NoAllocHelpers.ExtractArrayFromList(meshes), meshes.Count, false);\n        }\n    }\n}\n","sourceCodeStart":41,"sourceCodeEnd":71,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/MeshUtility.bindings.cs#L41-L71","documentation":"Thrown by the Mesh[] overload of AcquireReadOnlyMeshData when the meshes array is null. The method acquires read-only CPU access to the mesh vertex/index data of multiple meshes and requires a non-null array.","triggerScenarios":"Calling AcquireReadOnlyMeshData((Mesh[])null), or passing an array reference that was never allocated. Distinct from the single-Mesh overload and the List<Mesh> overload, which have their own null checks.","commonSituations":"Editor tooling that collects meshes from a hierarchy and passes the result without checking for null (e.g. when no meshes were found). A field defaulting to null passed directly.","solutions":["Allocate and populate the array before calling; if no meshes exist, handle that case explicitly rather than passing null.","Null-check the array and log which source produced null.","Use the List<Mesh> overload if you already have a list, to avoid manual array management."],"exampleFix":"// before\nvar data = MeshUtility.AcquireReadOnlyMeshData(meshes);\n\n// after\nif (meshes == null || meshes.Length == 0) return;\nvar data = MeshUtility.AcquireReadOnlyMeshData(meshes);","handlingStrategy":"type-guard","validationCode":"if (meshes == null || meshes.Length == 0) return;","typeGuard":"static bool HasMeshes(Mesh[] m) => m != null && m.Length > 0;","tryCatchPattern":"try { var data = MeshUtility.AcquireReadOnlyMeshData(meshes); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"meshes\") { Debug.LogWarning(\"No meshes to acquire.\"); }","preventionTips":["Allocate the array before calling","Handle the no-meshes case explicitly","Prefer the List overload when applicable"],"tags":["unity","editor","mesh","argument-validation","mesh-data"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}