diff --git a/dat/outfit.xml b/dat/outfit.xml
index b1357b8..13924bd 100644
--- a/dat/outfit.xml
+++ b/dat/outfit.xml
@@ -365,7 +365,7 @@
125
-
+
12
9
diff --git a/src/map.c b/src/map.c
index d7ce5ed..a1d0bc5 100644
--- a/src/map.c
+++ b/src/map.c
@@ -21,6 +21,9 @@
#define BUTTON_WIDTH 60 /**< Map button width. */
#define BUTTON_HEIGHT 30 /**< Map button height. */
+#define MAP_LOOP_PROT 250 /**< Number of iterations max in pathfinding before
+ aborting. */
+
static double map_zoom = 1.; /**< Zoom of the map. */
static double map_xpos = 0.; /**< Map X position. */
static double map_ypos = 0.; /**< Map Y position. */
@@ -766,7 +769,7 @@ static void A_freeList(SysNode* first) {
}
StarSystem** map_getJumpPath(int* njumps, char* sysstart, char* sysend, int ignore_known) {
- int i, cost;
+ int i, j, cost;
StarSystem* sys, *ssys, *esys, **res;
@@ -792,7 +795,13 @@ StarSystem** map_getJumpPath(int* njumps, char* sysstart, char* sysend, int igno
cur = A_newNode(ssys, NULL);
open = A_add(open, cur); /* Initial open node is the start system. */
+ j = 0;
while((cur = A_lowest(open))->sys != esys) {
+ /* Break if infinite loop. */
+ j++;
+ if(j > MAP_LOOP_PROT)
+ break;
+
/* Get best from open and toss to closed. */
open = A_rm(open, cur->sys);
closed = A_add(closed, cur);
@@ -825,12 +834,17 @@ StarSystem** map_getJumpPath(int* njumps, char* sysstart, char* sysend, int igno
}
}
}
- /* Build the path backwards. */
- (*njumps) = A_g(cur);
- res = malloc(sizeof(StarSystem*) * (*njumps));
- for(i = 0; i < (*njumps); i++) {
- res[(*njumps)-i-1] = cur->sys;
- cur = cur->parent;
+ /* Build the path backwards if not broken from loop. */
+ if(j <= MAP_LOOP_PROT) {
+ (*njumps) = A_g(cur);
+ res = malloc(sizeof(StarSystem*) * (*njumps));
+ for(i = 0; i < (*njumps); i++) {
+ res[(*njumps)-i-1] = cur->sys;
+ cur = cur->parent;
+ }
+ } else {
+ (*njumps) = 0;
+ res = NULL;
}
/* Free the linked list. */