From 233b850daf653597abaa67c3700a792acedcd6e7 Mon Sep 17 00:00:00 2001 From: Andrii Danylchenko Date: Thu, 3 Nov 2022 21:16:49 +0200 Subject: [PATCH] NKAI: a few crash/hang fixes --- AI/Nullkiller/AIGateway.cpp | 4 ++++ AI/Nullkiller/Engine/Nullkiller.cpp | 2 +- AI/Nullkiller/Pathfinding/AINodeStorage.cpp | 2 +- lib/CPathfinder.cpp | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/AI/Nullkiller/AIGateway.cpp b/AI/Nullkiller/AIGateway.cpp index 6a6dfd299..92be1822a 100644 --- a/AI/Nullkiller/AIGateway.cpp +++ b/AI/Nullkiller/AIGateway.cpp @@ -774,8 +774,10 @@ void AIGateway::makeTurn() retrieveVisitableObjs(); } +#if NKAI_TRACE_LEVEL == 0 try { +#endif nullkiller->makeTurn(); //for debug purpose @@ -784,6 +786,7 @@ void AIGateway::makeTurn() if (h->movement) logAi->warn("Hero %s has %d MP left", h->name, h->movement); } +#if NKAI_TRACE_LEVEL == 0 } catch (boost::thread_interrupted & e) { @@ -795,6 +798,7 @@ void AIGateway::makeTurn() { logAi->debug("Making turn thread has caught an exception: %s", e.what()); } +#endif endTurn(); } diff --git a/AI/Nullkiller/Engine/Nullkiller.cpp b/AI/Nullkiller/Engine/Nullkiller.cpp index 8b3e56f21..9c0dcd132 100644 --- a/AI/Nullkiller/Engine/Nullkiller.cpp +++ b/AI/Nullkiller/Engine/Nullkiller.cpp @@ -307,7 +307,7 @@ void Nullkiller::executeTask(Goals::TTask task) { logAi->trace("Task %s completed", task->toString()); } - catch(std::exception & e) + catch(cannotFulfillGoalException & e) { logAi->debug("Failed to realize subgoal of type %s, I will stop.", taskDescr); logAi->debug("The error message was: %s", e.what()); diff --git a/AI/Nullkiller/Pathfinding/AINodeStorage.cpp b/AI/Nullkiller/Pathfinding/AINodeStorage.cpp index ee91b7b0c..916ff8240 100644 --- a/AI/Nullkiller/Pathfinding/AINodeStorage.cpp +++ b/AI/Nullkiller/Pathfinding/AINodeStorage.cpp @@ -1086,7 +1086,7 @@ void AINodeStorage::calculateTownPortal( for(const CGTownInstance * targetTown : towns) { // TODO: allow to hide visiting hero in garrison - if(targetTown->visitingHero) + if(targetTown->visitingHero && maskMap.find(targetTown->visitingHero.get()) != maskMap.end()) { auto basicMask = maskMap.at(targetTown->visitingHero.get()); bool heroIsInChain = (actor->chainMask & basicMask) != 0; diff --git a/lib/CPathfinder.cpp b/lib/CPathfinder.cpp index bc2fca93d..11f8959d0 100644 --- a/lib/CPathfinder.cpp +++ b/lib/CPathfinder.cpp @@ -339,7 +339,7 @@ void CPathfinder::calculatePaths() auto hlp = config->getOrCreatePathfinderHelper(source, gs); if(hlp->isHeroPatrolLocked()) - break; + continue; pq.push(initialNode); }