When i trying to use rvo obstacle system with lots of rov obstacles, it always crash, but it works fine with few rvo obstacles. I debug the code and found that there is a array overflow bug at: Pathfinding.RVO.Sampled.Agent.CalculateVelocity.

```
if (context.vos.Length < neighbours.Count+simulator.obstacles.Count)
{
context.vos = new VO[Mathf.Max(context.vos.Length*2, neighbours.Count+simulator.obstacles.Count)];
}
```

which the “vertex count of obstacles in total” should be used instead of obstacles count, something like this:

```
// Fix array overflow bug.
if (context.vos.Length < neighbours.Count + simulator.ObstaclesVertexCount)
{
context.vos = new VO[Mathf.Max(context.vos.Length * 2, neighbours.Count + simulator.ObstaclesVertexCount)];
}
```

“ObstaclesVertexCount” is the total vertex count with all of the obstacles.

In my temportary solution, i add a “vertexCount” for “ObstacleVertex”, in order to hold the total vertex count if the node is head of the obstacle list.

Add “obstaclesVertexCount” for Simulator.

Something like this in AddObstacle:

```
public ObstacleVertex AddObstacle (Vector3[] vertices, float height, Matrix4x4 matrix, RVOLayer layer = RVOLayer.DefaultObstacle) {
if (vertices == null) throw new System.ArgumentNullException("Vertices must not be null");
if (vertices.Length < 2) throw new System.ArgumentException("Less than 2 vertices in an obstacle");
ObstacleVertex first = null;
ObstacleVertex prev = null;
bool identity = matrix == Matrix4x4.identity;
//Don't interfere with ongoing calculations
if (Multithreading && doubleBuffering) for (int j = 0; j < workers.Length; j++) workers[j].WaitOne();
for (int i = 0; i < vertices.Length; i++) {
ObstacleVertex v = new ObstacleVertex();
if (first == null)
{
v.vertexCount = vertices.Length;
first = v;
}
else
{
v.vertexCount = 1;
prev.next = v;
}
v.prev = prev;
v.layer = layer;
//Premature optimization ftw!
v.position = identity ? vertices[i] : matrix.MultiplyPoint3x4(vertices[i]);
//v.thin = thin;
v.height = height;
prev = v;
}
prev.next = first;
first.prev = prev;
ObstacleVertex c = first;
do {
Vector3 dir = c.next.position - c.position;
c.dir = new Vector2(dir.x, dir.z).normalized;
c = c.next;
} while (c != first);
obstacles.Add(first);
obstaclesVertexCount += vertices.Length;
UpdateObstacles();
return first;
}
```

Hi @aron_granberg, maybe you can check this out at some time.