Missing tangents on some vertices

I’m calculating tangents for simple polygons using the method described here: Calculating Tangents (Vector4) - Unity Answers

Most of the tangents are good. However, some are missing. [21533-missing+tangents.jpg|21533]

In the attached diagram tangent vectors are in blue, normals in red. The three vertices on the top have no tangents (actually tangents of length zero) while the remaining vertices are fine. As a result, the bump mapping becomes smooth near the bad vertices.

This occurs on every polygon in the scene, and always only on the vertices on the extreme +x edge of the polygons.

Any ideas?

Mission accomplished!

I was using the first code here: Calculating Tangents (Vector4) - Unity Answers , but the triangles array is too small and data was missing.

But I should have been using the more efficient (and commented) code a little further down the page that does not try to truncate the triangle array.