Unity crash after Invoke function

HI, I wrote this code:

void generatePlatform()
    {
        if (platforms.Count >= 10 && pulled())
        {
            print("a");
            selectedPlatform.transform.localScale = new Vector3(selectedPlatform.transform.localScale.x, selectedPlatform.transform.localScale.y, w);
            selectedPlatform.transform.position = nextPos;
        }
        else
        {
            selectedPlatform = Instantiate(platform, nextPos, Quaternion.identity);
            selectedPlatform.transform.localScale = new Vector3(selectedPlatform.transform.localScale.x, selectedPlatform.transform.localScale.y, w);
            selectedPlatform.name = "Platform" + platforms.Count;
            addPlatform();
        }
        recallFunction();
    }

    public void addPlatform()
    {
        if(!platforms.Contains(selectedPlatform))
        {
            platforms.Add(selectedPlatform);
        }
    }

    bool pullPlatform()
    {
        int i = 0;
        while(i <= platforms.Count)
        {
            if (platforms.transform.position.z < player.transform.position.z)
            {
                selectedPlatform = platforms;
                i++;
                return true;
            }
        }
        return false;
    }

    void recallFunction()
    {
        Invoke("randomValues", 1f);
    }

    bool pulled()
    {
        int i = 0;
        while(i <= platforms.Count)
        {
            if (platforms.transform.position.z < player.transform.position.z)
            {
                selectedPlatform = platforms;
                i++;
                return true;
            }
        }
        return false;
    }
}

And unity all the time crashes after it’s
Invoke function when it’s return true in the if statement:
if (platforms.Count >= 10 && pulled())
please help it never happened before
Thanks for the help.

Use code tags! Using code tags properly - Unity Engine - Unity Discussions

And Unity crashes or freezes up?

freezes up

Ok, but still fix your post with code tags. Hard to read as is.

If it freezes up, you have an infinite loop probably. I would make sure you’re not getting stuck in your while loops. If it never exits a while loop, it will freeze up.