Im having an issue with a custom editor script pausing the whole editor with the little applicaton.message?

I tried two seperate scripts to try a different approach and see which is easier to logically go about finding and it pauses on only one of them. I sat for at least a minute waiting for it to finish but it didn’t.
This is the code for the actual script that runs.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[ExecuteInEditMode]
public class FaceFinder : MonoBehaviour
{
    public Face[] faced;
  
    public void FindFaces()
    {
        List<Face> faces = new List<Face>();
        Mesh mesh = this.GetComponent<MeshFilter>().sharedMesh;
        Debug.Log("Finding");
        for(int i =0; i < mesh.triangles.Length; i += 3)
        {
            Vector3 v1 = mesh.vertices[mesh.triangles[i + 0]];
            Vector3 v2 = mesh.vertices[mesh.triangles[i + 1]];
            Vector3 v3 = mesh.vertices[mesh.triangles[i + 2]];
            Vector3[] sorted = returnOrdered(v1, v2, v3);
            Vector3 line1 = (sorted[1] - sorted[0]);
            Vector3 line2 = (sorted[1] - sorted[2]);
            Vector3 cross = Vector3.Cross(line2, line1);

            for (int j = 0; j < mesh.triangles.Length; i += 3)
            {
                if (j != i)
                {
                    Vector3 vertex1 = mesh.vertices[mesh.triangles[j + 0]];
                    Vector3 vertex2 = mesh.vertices[mesh.triangles[j + 1]];
                    Vector3 vertex3 = mesh.vertices[mesh.triangles[j + 2]];
                    Vector3[] sorted1 = returnOrdered(vertex1, vertex2, vertex3);
                    Vector3 line3 = (sorted[1] - sorted[0]);
                    Vector3 line4 = (sorted[1] - sorted[2]);
                    Vector3 cross2 = Vector3.Cross(line3, line4);
                    if (cross == cross2)
                    {
                        //Vector3[] matched = FindAndRemoveMatched(sorted, sorted1);
                        Face f = new Face();
                        Vector3[] matched = { v1, v2, v3, vertex1 };
                        f.vertices = matched;
                        f.triangles = new int[] { i, j };
                        faces.Add(f);
                    }
                }
            }
        }

        faced = faces.ToArray();
    }

    public Vector3[] FindAndRemoveMatched(Vector3[] array1,Vector3[] array2)
    {
        List<Vector3> newList = new List<Vector3>();
        newList.AddRange(array1);
        newList.AddRange(array2);
        Vector3[] combined = newList.ToArray();
        
        for(int i =0; i < combined.Length; i++)
        {
            for(int k = i + 1; k < combined.Length; k++)
            {
                if (combined *== combined[k])*

{
newList.Remove(combined*);*
}

}
}
Debug.Log(newList.Count);
return newList.ToArray();

}
Vector3[] returnOrdered(Vector3 v1, Vector3 v2, Vector3 v3)
{
bool sorted = false;
Vector3[] vecArry = new Vector3[3] { v1, v2, v3 };
while (sorted == false)
{
sorted = true;
for (int i = 0; i < vecArry.Length - 1; i++)
{
if (vecArry*.magnitude > vecArry[i + 1].magnitude)*
{
vecArry = vecArry[i + 1];
sorted = false;
}
}
}

return vecArry;
}
}

[System.Serializable]
public class Face{

public Vector3[] vertices;
//Should only be two but whatever.
public int[] triangles;
public Face()
{

}

}
Here is the script for the editor button former.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(FaceFinder))]
public class FaceFinderEditor : Editor
{
public override void OnInspectorGUI()
{
DrawDefaultInspector();

FaceFinder generateField = (FaceFinder)target;
if (GUILayout.Button(“Find”))
{
generateField.FindFaces();
}

}
}

@hellojbb1234

for(int i =0; i < mesh.triangles.Length; i += 3)
         {
             ...
 
             for (int j = 0; j < mesh.triangles.Length; i += 3)

Not sure how large triangles.Length is but nesting a for loop inside of a for loop of the same magnitude is potentially detrimental to performance.

returnOrdered nests a for loop within a while loop.

Currently implemented you have two nested for loops within a nested for loop.

If line 38 was uncommented you would have another nested loop running.

See if you can reduce some loop layers.

For some practice on this concept I would go check out HackerRank.com.