From c05ffb22bd4d87ec1c69639cfc63fa56f7037381 Mon Sep 17 00:00:00 2001 From: SamuXarick <43006711+SamuXarick@users.noreply.github.com> Date: Sun, 17 Dec 2023 21:50:53 +0000 Subject: [PATCH] Fix #10452: Don't let AyStar max_search_nodes unattended when initializing (#11544) Add a constant with the default value of 10000 and have the pathfinding settings refer to it. Add a preventative method to AyStar when it's initializing, to limit the number of max_search_nodes if left unattended. --- src/pathfinder/npf/aystar.cpp | 3 +++ src/pathfinder/npf/aystar.h | 2 ++ src/pathfinder/pathfinder_type.h | 1 + src/table/settings/pathfinding_settings.ini | 4 ++-- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pathfinder/npf/aystar.cpp b/src/pathfinder/npf/aystar.cpp index 698b8183ac..b52b762d84 100644 --- a/src/pathfinder/npf/aystar.cpp +++ b/src/pathfinder/npf/aystar.cpp @@ -301,4 +301,7 @@ void AyStar::Init(Hash_HashProc hash, uint num_buckets) * When that one gets full it reserves another one, till this number * That is why it can stay this high */ this->openlist_queue.Init(102400); + + /* Set a reasonable default limit */ + this->max_search_nodes = AYSTAR_DEF_MAX_SEARCH_NODES; } diff --git a/src/pathfinder/npf/aystar.h b/src/pathfinder/npf/aystar.h index 7046fcf570..5bd2368172 100644 --- a/src/pathfinder/npf/aystar.h +++ b/src/pathfinder/npf/aystar.h @@ -20,6 +20,8 @@ #include "../../tile_type.h" #include "../../track_type.h" +static const int AYSTAR_DEF_MAX_SEARCH_NODES = 10000; ///< Reference limit for #AyStar::max_search_nodes + /** Return status of #AyStar methods. */ enum AystarStatus { AYSTAR_FOUND_END_NODE, ///< An end node was found. diff --git a/src/pathfinder/pathfinder_type.h b/src/pathfinder/pathfinder_type.h index eb0381d8a3..379297adfc 100644 --- a/src/pathfinder/pathfinder_type.h +++ b/src/pathfinder/pathfinder_type.h @@ -11,6 +11,7 @@ #define PATHFINDER_TYPE_H #include "../tile_type.h" +#include "npf/aystar.h" /** Length (penalty) of one tile with NPF */ static const int NPF_TILE_LENGTH = 100; diff --git a/src/table/settings/pathfinding_settings.ini b/src/table/settings/pathfinding_settings.ini index df2494d351..e06e8d501b 100644 --- a/src/table/settings/pathfinding_settings.ini +++ b/src/table/settings/pathfinding_settings.ini @@ -168,7 +168,7 @@ cat = SC_EXPERT [SDT_VAR] var = pf.npf.npf_max_search_nodes type = SLE_UINT -def = 10000 +def = AYSTAR_DEF_MAX_SEARCH_NODES min = 500 max = 100000 cat = SC_EXPERT @@ -325,7 +325,7 @@ cat = SC_EXPERT var = pf.yapf.max_search_nodes type = SLE_UINT from = SLV_28 -def = 10000 +def = AYSTAR_DEF_MAX_SEARCH_NODES min = 500 max = 1000000 cat = SC_EXPERT