[Change] Avoid a theoretical infinite loop plus a memleak in the map.
This commit is contained in:
parent
14fc795816
commit
fbc7169d21
@ -365,7 +365,7 @@
|
|||||||
<energy_regen>125</energy_regen>
|
<energy_regen>125</energy_regen>
|
||||||
</specific>
|
</specific>
|
||||||
</outfit>
|
</outfit>
|
||||||
<outfit name="Shield Capacitator">
|
<outfit name="Shield Capacitor">
|
||||||
<general>
|
<general>
|
||||||
<max>12</max>
|
<max>12</max>
|
||||||
<tech>9</tech>
|
<tech>9</tech>
|
||||||
|
28
src/map.c
28
src/map.c
@ -21,6 +21,9 @@
|
|||||||
#define BUTTON_WIDTH 60 /**< Map button width. */
|
#define BUTTON_WIDTH 60 /**< Map button width. */
|
||||||
#define BUTTON_HEIGHT 30 /**< Map button height. */
|
#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_zoom = 1.; /**< Zoom of the map. */
|
||||||
static double map_xpos = 0.; /**< Map X position. */
|
static double map_xpos = 0.; /**< Map X position. */
|
||||||
static double map_ypos = 0.; /**< Map Y 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) {
|
StarSystem** map_getJumpPath(int* njumps, char* sysstart, char* sysend, int ignore_known) {
|
||||||
int i, cost;
|
int i, j, cost;
|
||||||
|
|
||||||
StarSystem* sys, *ssys, *esys, **res;
|
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);
|
cur = A_newNode(ssys, NULL);
|
||||||
open = A_add(open, cur); /* Initial open node is the start system. */
|
open = A_add(open, cur); /* Initial open node is the start system. */
|
||||||
|
|
||||||
|
j = 0;
|
||||||
while((cur = A_lowest(open))->sys != esys) {
|
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. */
|
/* Get best from open and toss to closed. */
|
||||||
open = A_rm(open, cur->sys);
|
open = A_rm(open, cur->sys);
|
||||||
closed = A_add(closed, cur);
|
closed = A_add(closed, cur);
|
||||||
@ -825,12 +834,17 @@ StarSystem** map_getJumpPath(int* njumps, char* sysstart, char* sysend, int igno
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Build the path backwards. */
|
/* Build the path backwards if not broken from loop. */
|
||||||
(*njumps) = A_g(cur);
|
if(j <= MAP_LOOP_PROT) {
|
||||||
res = malloc(sizeof(StarSystem*) * (*njumps));
|
(*njumps) = A_g(cur);
|
||||||
for(i = 0; i < (*njumps); i++) {
|
res = malloc(sizeof(StarSystem*) * (*njumps));
|
||||||
res[(*njumps)-i-1] = cur->sys;
|
for(i = 0; i < (*njumps); i++) {
|
||||||
cur = cur->parent;
|
res[(*njumps)-i-1] = cur->sys;
|
||||||
|
cur = cur->parent;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
(*njumps) = 0;
|
||||||
|
res = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free the linked list. */
|
/* Free the linked list. */
|
||||||
|
Loading…
Reference in New Issue
Block a user