mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2026-04-27 20:41:46 +00:00
Update pointers to nodes when the nodesarray is reallocated.
Fixes crash in Gust Planet.
This commit is contained in:
parent
07cf9cddf1
commit
c7a00d4800
1 changed files with 33 additions and 2 deletions
|
|
@ -472,13 +472,44 @@ boolean K_PathfindAStar(path_t *const path, pathfindsetup_t *const pathfindsetup
|
||||||
// Reallocate nodesarray if it's full
|
// Reallocate nodesarray if it's full
|
||||||
if (nodesarraycount >= pathfindsetup->nodesarraycapacity)
|
if (nodesarraycount >= pathfindsetup->nodesarraycapacity)
|
||||||
{
|
{
|
||||||
|
pathfindnode_t *nodesarrayrealloc = NULL;
|
||||||
pathfindsetup->nodesarraycapacity = pathfindsetup->nodesarraycapacity * 2;
|
pathfindsetup->nodesarraycapacity = pathfindsetup->nodesarraycapacity * 2;
|
||||||
nodesarray = Z_Realloc(nodesarray, pathfindsetup->nodesarraycapacity * sizeof(pathfindnode_t), PU_STATIC, NULL);
|
nodesarrayrealloc = Z_Realloc(nodesarray, pathfindsetup->nodesarraycapacity * sizeof(pathfindnode_t), PU_STATIC, NULL);
|
||||||
|
|
||||||
if (nodesarray == NULL)
|
if (nodesarrayrealloc == NULL)
|
||||||
{
|
{
|
||||||
I_Error("K_PathfindAStar: Out of memory reallocating nodes array.");
|
I_Error("K_PathfindAStar: Out of memory reallocating nodes array.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Need to update pointers in closedset, openset, and node "camefrom" if nodesarray moved.
|
||||||
|
if (nodesarray != nodesarrayrealloc)
|
||||||
|
{
|
||||||
|
size_t i = 0U;
|
||||||
|
size_t arrayindex = 0U;
|
||||||
|
for (i = 0U; i < closedsetcount; i++)
|
||||||
|
{
|
||||||
|
arrayindex = closedset[i] - nodesarray;
|
||||||
|
closedset[i] = &nodesarrayrealloc[arrayindex];
|
||||||
|
}
|
||||||
|
for (i = 0U; i < openset.count; i++)
|
||||||
|
{
|
||||||
|
arrayindex = ((pathfindnode_t *)(openset.array[i].data)) - nodesarray;
|
||||||
|
openset.array[i].data = &nodesarrayrealloc[arrayindex];
|
||||||
|
}
|
||||||
|
for (i = 0U; i < nodesarraycount; i++)
|
||||||
|
{
|
||||||
|
if (nodesarrayrealloc[i].camefrom != NULL)
|
||||||
|
{
|
||||||
|
arrayindex = nodesarrayrealloc[i].camefrom - nodesarray;
|
||||||
|
nodesarrayrealloc[i].camefrom = &nodesarrayrealloc[arrayindex];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
arrayindex = currentnode - nodesarray;
|
||||||
|
currentnode = &nodesarrayrealloc[arrayindex];
|
||||||
|
}
|
||||||
|
|
||||||
|
nodesarray = nodesarrayrealloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the new node and add it to the nodes array and open set
|
// Create the new node and add it to the nodes array and open set
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue