Fix infinite loop in freeform AI module
Merge pull request #5365 from volas/master

Fix infinite loop