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

Fix for rare crash in previous commit.

This commit is contained in:
DjWarmonger 2014-02-05 09:04:09 +00:00
parent c708a631c1
commit 5e58027496

View File

@ -1332,6 +1332,20 @@ void VCAI::wander(HeroPtr h)
if(!dest)
{
logAi->debugStream() << boost::format("Visit attempt made the object (id=%d) gone...") % dest.id.getNum();
//TODO: refactor removing deleted objects from the list
std::vector<const CGObjectInstance *> hlp;
retreiveVisitableObjs(hlp, true);
auto shouldBeErased = [&](const CGObjectInstance *obj) -> bool
{
if(!vstd::contains(hlp, obj))
{
return true;
}
return false;
};
erase_if(dests, shouldBeErased);
}
else
{
@ -1341,23 +1355,7 @@ void VCAI::wander(HeroPtr h)
}
else
{
//if (dest)
erase_if_present(dests, dest);
////TODO: refactor removing deleted objects from the list
//std::vector<const CGObjectInstance *> hlp;
//retreiveVisitableObjs(hlp, true);
//auto shouldBeErased = [&](const CGObjectInstance *obj) -> bool
//{
// if(!vstd::contains(hlp, obj))
// {
// return true;
// }
// return false;
//};
//erase_if(dests, shouldBeErased);
erase_if_present(dests, dest); //why that fails sometimes when removing monsters?
boost::sort(dests, isCloser); //find next closest one
}
}