Index Out of Bounds Line Render

So i get an error on path.SetPosition (i, newPos); saying index is out of bounds? I am not sure why or how to solve this. the variable newPos is a vector 3 updated as the game object follows pose. I know its working because instantiate an object when The gameobject pose is moving. I can also print the current vector 3 of the Newpos. so why the error? I just want to build a line render as the object moves to then carry that over to the next scene, but cant get pass this error

Thanks for the help in advance.

    private Vector3 lastPos;
	private Vector3 newPos;
	private bool isMove;
	private int i;
	private LineRenderer path;

	public GameObject wayPoint;
	public GameObject pose;

	void Start ()
	{
		i = 0;
		path = GetComponent<LineRenderer> ();
		StartCoroutine (trackMove ());
	}

	IEnumerator trackMove()
	{


			lastPos = pose.transform.position;
			yield return new WaitForSeconds (0.5f);
			newPos = pose.transform.position;
			

			if (lastPos != newPos) {
				Debug.Log ("Im moving");
				path.SetVertexCount (i);
				path.SetPosition (i, newPos);
				i++;
			} 
			else if (lastPos == newPos) {
				Debug.Log ("not moving);
                           isMove = false;
			}
			StartCoroutine (trackMove ());
	}

Figure it out. I couldnt have the vertex count and path position both equal to the same variable. Since the variable of vertex counts starts at 0 and the path position starts at 1. So I when it was updating it kept creating one more vertex that there was a position. to fix it I could either set vertex to one, but instead I created another int var and set that equal to 1.

So the path position is equal to one
and the vertex count is equal to 0;

problem was solved