1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +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) if(!dest)
{ {
logAi->debugStream() << boost::format("Visit attempt made the object (id=%d) gone...") % dest.id.getNum(); 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 else
{ {
@ -1341,23 +1355,7 @@ void VCAI::wander(HeroPtr h)
} }
else else
{ {
//if (dest) erase_if_present(dests, dest); //why that fails sometimes when removing monsters?
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);
boost::sort(dests, isCloser); //find next closest one boost::sort(dests, isCloser); //find next closest one
} }
} }