# Fixed a pathfinder bug.

The pathfinder was pushing locations with negative coordinates (or
coordinates larger than the map size) onto the queue, which led to
memory corruption in CAStarEngine's node array and later a crash in its
destructor.

This was SVN commit r3923.
This commit is contained in:
Matei 2006-06-01 06:04:32 +00:00
parent bca1f982eb
commit bde2a0b0c7
2 changed files with 13 additions and 7 deletions

View File

@ -47,9 +47,7 @@ CAStarEngine::CAStarEngine(AStarGoalBase *goal)
CAStarEngine::~CAStarEngine()
{
if(mFlags) {
delete[] mFlags;
}
delete[] mFlags;
std::vector<AStarNode*>::iterator it;
for( it = usedNodes.begin(); it != usedNodes.end(); it++)
{
@ -344,8 +342,15 @@ float AStarGoalLowLevel::getTileCost( const CVector2D& loc1, const CVector2D& lo
bool AStarGoalLowLevel::isPassable( const CVector2D &loc, CPlayer* player )
{
CVector2D wloc = TilespaceToWorldspace(loc);
CTerrain* pTerrain = g_Game->GetWorld()->GetTerrain();
int size = pTerrain->GetTilesPerSide();
if( loc.x<0 || loc.y<0 || loc.x>=size || loc.y>=size )
{
return false;
}
CVector2D wloc = TilespaceToWorldspace(loc);
float slope = pTerrain->getSlope(wloc.x, wloc.y);
if ( slope < MAXSLOPE )
{
@ -396,7 +401,8 @@ std::vector<CVector2D> AStarGoalLowLevel::getNeighbors( const CVector2D &loc, CP
inline AStarNodeFlag* CAStarEngine::GetFlag(const CVector2D &loc)
{
return mFlags + (mFlagArraySize * (long)loc.x) + (long)loc.y;
debug_assert(loc.x>=0 && loc.y>=0 && loc.x<mFlagArraySize && loc.y<mFlagArraySize);
return mFlags + (mFlagArraySize * (long)loc.x + (long)loc.y);
}

View File

@ -60,7 +60,7 @@ class CAStarEngine
public:
CAStarEngine();
CAStarEngine(AStarGoalBase* goal);
~CAStarEngine();
virtual ~CAStarEngine();
void setGoal(AStarGoalBase* goal) { mGoal = goal; }
@ -154,7 +154,7 @@ public:
{
mGoal = new AStarGoalLowLevel;
}
~CAStarEngineLowLevel()
virtual ~CAStarEngineLowLevel()
{
delete mGoal;
}