Procedural mesh AABB error on OSX
Hi there, I've been having a lot of trouble solving an error I've been getting during runtime. When the function I've made called BuildBezierPlane() is called once, the editor will spit out the errors:
Invalid AABB aabb
Invalid AABB result
Invalid AABB a
Assertion failed on expression: 'IsFinite(outDistanceForSort)'
if it is called more than once, it will not return any errors, but it will skip the first mesh generated by this function. If a different function that also builds a mesh in the same way is called at the same time instead of this one, it will build fine.
This snippet of code will generate a quad perfectly if called instead of BuildBezierPlane: protected void BuildQuad(MeshBuilder meshBuilder, Vector3 offset, float width, float length) { meshBuilder.Vertices.Add(new Vector3(0.0f, 0.0f, 0.0f) + offset); meshBuilder.UVs.Add(new Vector2(0.0f, 0.0f)); meshBuilder.Normals.Add(Vector3.up);
meshBuilder.Vertices.Add(new Vector3(0.0f, 0.0f, length) + offset);
meshBuilder.UVs.Add(new Vector2(0.0f, 1.0f));
meshBuilder.Normals.Add(Vector3.up);
meshBuilder.Vertices.Add(new Vector3(width, 0.0f, length) + offset);
meshBuilder.UVs.Add(new Vector2(1.0f, 1.0f));
meshBuilder.Normals.Add(Vector3.up);
meshBuilder.Vertices.Add(new Vector3(width, 0.0f, 0.0f) + offset);
meshBuilder.UVs.Add(new Vector2(1.0f, 0.0f));
meshBuilder.Normals.Add(Vector3.up);
int baseIndex = meshBuilder.Vertices.Count - 4;
meshBuilder.AddTriangle(baseIndex, baseIndex + 1, baseIndex + 2);
meshBuilder.AddTriangle(baseIndex, baseIndex + 2, baseIndex + 3);
}
This snippet here will return errors if called only once:
public void BuildBezierPlane(MeshBuilder meshBuilder, Curve top, Curve bottom, Curve right, Curve left)
{
int baseCount = meshBuilder.Vertices.Count;
int width = bottom.Positions.Count;
int height = left.Positions.Count;
if (height > 1 && width > 1)
{
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
float t = y / (height - 1.0f);
Vector3 p0 = bottom.Positions[x];
Vector3 p1 = Vector3.Lerp(left.Positions[width / 2], right.Positions[width / 2], y / (height - 1.0f));
Vector3 p2 = top.Positions[x];
Vector3 position = (1.0f - t) * (1.0f - t) * p0 + 2.0f * (1.0f - t) * t * p1 + t * t * p2;
position = new Vector3(x, y, 1);
meshBuilder.Vertices.Add(position);
Debug.Log("Positions: " + p0 + p1 + p2);
meshBuilder.UVs.Add(new Vector2(x / (width - 1.0f), y / (height - 1.0f)));
}
}
for (int ti = 0, vi = 0, y = 0; y < height; y++, vi++)
{
for (int x = 0; x < width; x++, ti += 6, vi++)
{
meshBuilder.AddTriangle(vi, vi + width + 1, vi + 1);
meshBuilder.AddTriangle(vi + 1, vi + width + 1, vi + width + 2);
}
}
}
else
{
return;
}
}
I've employed many fixes already suggested by the unity community on reddit and game development circles, but none of them have worked. Could this be a mac osx Mojave specific problem?
Your answer

Follow this Question
Related Questions
[Help Request] 2D Wave Generation & Animation 2 Answers
Problem with Procedural Mesh Generation 1 Answer
Mesh Creation at Runtime - Strange black artefacts 0 Answers
Different textures on different meshes but same material 0 Answers
Procedurally generated mesh having some faces that don't receive light 1 Answer