Hello everyone,
I’m currently facing a problem and don’t know how to resolve it…There is one function in my code that makes the game crash after a few seconds if it’s called every tick. I’m assuming it has something to do with improper memory management from my side since everything works perfectly fine if I don’t call this function anymore. Here’s what the function looks like:
/**
* returns all tiles which are no further than the specified distance (in grid coordinates, not reachability)
*/
TArray<ATile*> ULevelManager::GetTilesWithMaxDistance(ATile* StartTile, uint8 MaxDistance)
{
TArray<ATile*> CloseTiles;
for (ATile* Tile : this->Tiles)
{
int distance = UKismetMathLibrary::Abs(Tile->GridPosition.X - StartTile->GridPosition.X) + UKismetMathLibrary::Abs(Tile->GridPosition.Y - StartTile->GridPosition.Y);
if (distance <= MaxDistance)
{
CloseTiles.Add(Tile);
}
}
return CloseTiles;
}
Does anybode see why this function could cause a crash if it is called every tick?
Thank you for your help
Bugmee