The pathfinding behavior is very CPU intensive. In your code, you are using a loop inside which you are finding a path. This starts the process of finding a path repeatedly and you will eventually run out of processing power to complete the task so, it is no wonder the game is crashing. Have you read through the documentation and tutorials on pathfinding? If you had, you would see this is not how to use the behavior.
There is a really good tutorial on combining 2 behaviors to get an enemy to chase the player: https://www.scirra.com/tutorials/474/pa ... e-of-sight
Read through it. You may find an easy way to do what your are trying to do. Also, make sure to read all the documentation on the pathfinding behavior in the manual and check out a couple other tutorials.
I hope that gets you what you need and good luck with your project.