diff options
author | peter1138 <peter1138@openttd.org> | 2017-04-04 00:00:43 +0000 |
---|---|---|
committer | peter1138 <peter1138@openttd.org> | 2017-04-04 00:00:43 +0000 |
commit | bf4499c64316cd9272511138e1d0afd157abf15e (patch) | |
tree | 771b70348c559ea2b6e4e712a8098d298ca25777 /src | |
parent | 1eef97674cfa4d9e55bacee5241e804a1827dfe9 (diff) | |
download | openttd-bf4499c64316cd9272511138e1d0afd157abf15e.tar.xz |
(svn r27846) -Fix [FS#5926]: Infinite loop in pathfinder when checking safe waiting position from a waypoint.
Diffstat (limited to 'src')
-rw-r--r-- | src/pathfinder/yapf/yapf_costrail.hpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/pathfinder/yapf/yapf_costrail.hpp b/src/pathfinder/yapf/yapf_costrail.hpp index d9d89b12f..22103987a 100644 --- a/src/pathfinder/yapf/yapf_costrail.hpp +++ b/src/pathfinder/yapf/yapf_costrail.hpp @@ -418,9 +418,16 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th CFollowTrackRail ft(v); TileIndex t = cur.tile; Trackdir td = cur.td; + /* Arbitrary maximum tiles to follow to avoid infinite loops. */ + uint max_tiles = 20; while (ft.Follow(t, td)) { assert(t != ft.m_new_tile); t = ft.m_new_tile; + if (t == cur.tile || --max_tiles == 0) { + /* We looped back on ourself or found another loop, bail out. */ + td = INVALID_TRACKDIR; + break; + } if (KillFirstBit(ft.m_new_td_bits) != TRACKDIR_BIT_NONE) { /* We encountered a junction; it's going to be too complex to * handle this perfectly, so just bail out. There is no simple |