Skip to content

Commit

Permalink
Fix #10452: Don't let AyStar max_search_nodes unattended when initial…
Browse files Browse the repository at this point in the history
…izing

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 this is left unattended.
  • Loading branch information
SamuXarick committed Dec 16, 2023
1 parent 0b6a7dd commit e7b23a3
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/landscape.cpp
Expand Up @@ -1308,7 +1308,6 @@ static void BuildRiver(TileIndex begin, TileIndex end, TileIndex spring, bool ma
finder.FoundEndNode = River_FoundEndNode;
finder.user_target = &end;
finder.user_data = &user_data;
finder.max_search_nodes = _settings_game.pf.npf.npf_max_search_nodes;

finder.Init(River_Hash, 1 << RIVER_HASH_SIZE);

Expand Down
5 changes: 5 additions & 0 deletions src/pathfinder/npf/aystar.cpp
Expand Up @@ -301,4 +301,9 @@ 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);

/* Limit the number of nodes expanded by default
* This is a preventive method as this should never be left unattended
* It can be modified afterwards */
this->max_search_nodes = AYSTAR_MAX_SEARCH_NODES;
}
2 changes: 2 additions & 0 deletions src/pathfinder/npf/aystar.h
Expand Up @@ -20,6 +20,8 @@
#include "../../tile_type.h"
#include "../../track_type.h"

static const int AYSTAR_MAX_SEARCH_NODES = 12312; ///< Reference limit for #AyStar::max_search_nodes

/** Return status of #AyStar methods. */
enum AystarStatus {
AYSTAR_FOUND_END_NODE, ///< An end node was found.
Expand Down
1 change: 1 addition & 0 deletions src/pathfinder/pathfinder_type.h
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/table/settings/pathfinding_settings.ini
Expand Up @@ -168,7 +168,7 @@ cat = SC_EXPERT
[SDT_VAR]
var = pf.npf.npf_max_search_nodes
type = SLE_UINT
def = 10000
def = AYSTAR_MAX_SEARCH_NODES
min = 500
max = 100000
cat = SC_EXPERT
Expand Down Expand Up @@ -325,7 +325,7 @@ cat = SC_EXPERT
var = pf.yapf.max_search_nodes
type = SLE_UINT
from = SLV_28
def = 10000
def = AYSTAR_MAX_SEARCH_NODES
min = 500
max = 1000000
cat = SC_EXPERT
Expand Down

0 comments on commit e7b23a3

Please sign in to comment.