1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00

Fix adventure map movement segfault in some scenarios

This commit is contained in:
Vadim Markovtsev 2015-10-31 20:23:13 +03:00
parent fa8a282696
commit e6e975e9ef
3 changed files with 24 additions and 23 deletions

View File

@ -1534,7 +1534,9 @@ void CAdvMapInt::tileHovered(const int3 &mapPos)
} }
else if(const CGHeroInstance *h = curHero()) else if(const CGHeroInstance *h = curHero())
{ {
const CGPathNode *pnode = LOCPLINT->cb->getPathsInfo(h)->getPathInfo(mapPos); int3 mapPosCopy = mapPos;
const CGPathNode *pnode = LOCPLINT->cb->getPathsInfo(h)->getPathInfo(mapPosCopy);
assert(pnode);
int turns = pnode->turns; int turns = pnode->turns;
vstd::amin(turns, 3); vstd::amin(turns, 3);
@ -1862,4 +1864,3 @@ void CAdvMapInt::WorldViewOptions::adjustDrawingInfo(MapDrawingInfo& info)
info.additionalIcons = &iconPositions; info.additionalIcons = &iconPositions;
} }

View File

@ -2899,11 +2899,11 @@ bool CGPathNode::reachable() const
return turns < 255; return turns < 255;
} }
const CGPathNode * CPathsInfo::getPathInfo( int3 tile ) const const CGPathNode * CPathsInfo::getPathInfo( const int3& tile ) const
{ {
boost::unique_lock<boost::mutex> pathLock(pathMx); boost::unique_lock<boost::mutex> pathLock(pathMx);
if (tile.x >= sizes.x || tile.y >= sizes.y || tile.z >= sizes.z ||
if (tile.x >= sizes.x || tile.y >= sizes.y || tile.z >= sizes.z) tile.x < 0 || tile.y < 0 || tile.z < 0)
return nullptr; return nullptr;
return &nodes[tile.x][tile.y][tile.z]; return &nodes[tile.x][tile.y][tile.z];
} }

View File

@ -158,7 +158,7 @@ struct DLL_LINKAGE CPathsInfo
int3 sizes; int3 sizes;
CGPathNode ***nodes; //[w][h][level] CGPathNode ***nodes; //[w][h][level]
const CGPathNode * getPathInfo( int3 tile ) const; const CGPathNode * getPathInfo( const int3& tile ) const;
bool getPath(const int3 &dst, CGPath &out) const; bool getPath(const int3 &dst, CGPath &out) const;
int getDistance( int3 tile ) const; int getDistance( int3 tile ) const;
CPathsInfo(const int3 &Sizes); CPathsInfo(const int3 &Sizes);