Bugfix: fix crash in some circumstances caused by Avoid crossing perimeters. #2271