Store Player Position and reycast it for deleting triangle return wrong triangle index

Hi everyone,
i’m new with unity and i’m programming a lot for learn but now i encountered a problem.
I need to get the Triangle Index of specific mesh (in specific layer) for destroiyng it when a player walking on.
i Try this code and Attach to the mesh i want to “destroy” but when the condition is triggered the deleted Triangles are not correct.
What i do is start collect the position of character at colision enter and stop it at collision exit then i need to destroy all the triangles in the collected position.
First code is very simple:
I set a condition for update

void OnCollisionEnter(Collision collision)
    {
        entered= true;
      
     
    }

After that in te Update function if entered is true i collect every Player Vector3 position:

if (entered)
        {
            if(last_position!= player.transform.position)
            {
                last_position= player.transform.position;
             
             
            
                position.Add(last_position);
             
            }
         
}

Now in the exit collision event i do this:

 entered= false;
       
        int layerMask = 1 << 8;
     
        layerMask = ~layerMask;
        int j = 0;
   

        RaycastHit hit;
        Ray ray;
        while (j < position.Count)
        {
          
         
            if (Physics.Raycast(position[j], Vector3.down, out hit, 100,layerMask))
            {
            
                delete_triangle(hit.triangleIndex);
            }
        }
      

     
        position.Clear();

And this is the delete_triangle function where i receive an error “IndexOutOfRangeException: Index was outside the bounds of the array” at the below marked line and i notice that the Triangle Index is always -1

Destroy(this.gameObject.GetComponent<MeshCollider>());
        mesh = GetComponent<MeshFilter>().mesh;
        int[] old_trangle = mesh.triangles;
        int[] new_triangle = new int[mesh.triangles.Length - 3];

        int i = 0;
        int j = 0;
        while (j < old_trangle.Length)
        {
            if (j != triangle_index * 3)
            {
               [COLOR=#ff0000] new_triangle [i++] = old_trangle[j++];[/COLOR]
                new_triangle [i++] = old_trangle[j++];
                new_triangle [i++] = old_trangle[j++];
            }
            else
            {
                j += 3;
            }

         
        }

        this.gameObject.AddComponent<MeshCollider>();
        transform.GetComponent<MeshFilter>().mesh.triangles = new_triangle ;

Thank you in advance for your help

So,
i figure out how to do this but now i have another problem.
The new setup is that i save all the position i want to reycast for find triangle to delete but the deleted triangles are wrong.
The loop is:

int layer_mask = LayerMask.GetMask("SafeZone");
        RaycastHit hit;
   
          int k = 0;
 
        int layer_mask = LayerMask.GetMask("SafeZone");
        while (k < position.Count)
        {
   
            if (Physics.Raycast(position[k], -Vector3.up, out hit, Mathf.Infinity, layer_mask))
            {
              Debug.DrawRay(position[k], -Vector3.up * hit.distance, Color.yellow,100);
               delete_triangle(hit.triangleIndex);
            }
            k++;
        }
        position.Clear();

The delete_triangle function is:

void delete_triangle(int index)
    {
    
        Destroy(safezone.gameObject.GetComponent<MeshCollider>());
        Mesh mesh = safezone.transform.GetComponent<MeshFilter>().mesh;
        mesh.MarkDynamic();
   
        int[] old_triangle = mesh.triangles;
        int[] new_triangle = new int[mesh.triangles.Length-3];
   
        int i = 0;
        int j = 0;
   
        while (j < old_triangle.Length)
        {
            if (j != index*3)
            {
           
                new_triangle[i++] = old_triangle[j++];
                new_triangle[i++] = old_triangle[j++];
                new_triangle[i++] = old_triangle[j++];
            }
            else
            {
                j += 3;
            }
       
        }
        safezone.gameObject.layer = 8;
        safezone.transform.GetComponent<MeshFilter>().mesh.triangles = new_triangle ;
        safezone.gameObject.AddComponent<MeshCollider>();
    }

Now for testing purpose i draw a line where the postion trigger the hit and as you will notice the new mesh is wrong:
5961467--639164--upload_2020-6-10_9-25-11.png

Nobody can help me?