From 67e192375633aa7ca1fa4e8fb0c26b3d602a7586 Mon Sep 17 00:00:00 2001 From: Andrettin Date: Thu, 14 Jan 2016 00:44:03 +0100 Subject: [PATCH] Some safety measures for the pathfinding code --- src/include/unit_find.h | 6 ++++++ src/pathfinder/astar.cpp | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/include/unit_find.h b/src/include/unit_find.h index 71df88a9b..01ef4d4e6 100644 --- a/src/include/unit_find.h +++ b/src/include/unit_find.h @@ -205,6 +205,12 @@ class CUnitTypeFinder bool operator()(const CUnit *const unit) const { const CUnitType &type = *unit->Type; + //Wyrmgus start + if (!&type) { + fprintf(stderr, "CUnitTypeFinder Error: Unit's type is NULL.\n"); + return false; + } + //Wyrmgus end if (type.BoolFlag[VANISHES_INDEX].value || (unitTypeType != static_cast(-1) && type.UnitType != unitTypeType)) { return false; } diff --git a/src/pathfinder/astar.cpp b/src/pathfinder/astar.cpp index 10eba8bdc..8436c7779 100644 --- a/src/pathfinder/astar.cpp +++ b/src/pathfinder/astar.cpp @@ -592,6 +592,12 @@ static int CostMoveToCallBack_Default(unsigned int index, const CUnit &unit) */ static inline int CostMoveTo(unsigned int index, const CUnit &unit) { + //Wyrmgus start + if (!&unit) { + fprintf(stderr, "Error in CostMoveTo(unsigned int index, const CUnit &unit): Unit is NULL.\n"); + return -1; + } + //Wyrmgus end int *c = &CostMoveToCache[index]; if (*c != CacheNotSet) { return *c; @@ -1040,7 +1046,11 @@ int AStarFindPath(const Vec2i &startPos, const Vec2i &goalPos, int gw, int gh, // Outside the map or can't be entered. if (endPos.x < 0 || endPos.x + tilesizex - 1 >= AStarMapWidth - || endPos.y < 0 || endPos.y + tilesizey - 1 >= AStarMapHeight) { + //Wyrmgus start +// || endPos.y < 0 || endPos.y + tilesizey - 1 >= AStarMapHeight) { + || endPos.y < 0 || endPos.y + tilesizey - 1 >= AStarMapHeight + || !Map.Info.IsPointOnMap(endPos)) { + //Wyrmgus end continue; }