Browse Source

Fix deadlock in AI on attempt to exit to main menu while in combat

Ivan Savenko 6 months ago
parent
commit
246d7e39a3
2 changed files with 8 additions and 2 deletions
  1. 6 1
      AI/Nullkiller/AIGateway.cpp
  2. 2 1
      AI/Nullkiller/AIGateway.h

+ 6 - 1
AI/Nullkiller/AIGateway.cpp

@@ -67,6 +67,7 @@ struct SetGlobalState
 #define MAKING_TURN SET_GLOBAL_STATE(this)
 
 AIGateway::AIGateway()
+	:status(this)
 {
 	LOG_TRACE(logAi);
 	destinationTeleport = ObjectInstanceID();
@@ -1676,7 +1677,8 @@ void AIGateway::validateObject(ObjectIdRef obj)
 	}
 }
 
-AIStatus::AIStatus()
+AIStatus::AIStatus(AIGateway * gateway)
+	: gateway(gateway)
 {
 	battle = NO_BATTLE;
 	havingTurn = false;
@@ -1758,7 +1760,10 @@ void AIStatus::waitTillFree()
 {
 	std::unique_lock<std::mutex> lock(mx);
 	while(battle != NO_BATTLE || !remainingQueries.empty() || !objectsBeingVisited.empty() || ongoingHeroMovement)
+	{
 		cv.wait_for(lock, std::chrono::milliseconds(10));
+		gateway->nullkiller->makingTurnInterrupption.interruptionPoint();
+	}
 }
 
 bool AIStatus::haveTurn()

+ 2 - 1
AI/Nullkiller/AIGateway.h

@@ -31,6 +31,7 @@ namespace NKAI
 
 class AIStatus
 {
+	AIGateway * gateway;
 	std::mutex mx;
 	std::condition_variable cv;
 
@@ -44,7 +45,7 @@ class AIStatus
 	bool havingTurn;
 
 public:
-	AIStatus();
+	AIStatus(AIGateway * gateway);
 	~AIStatus();
 	void setBattle(BattleState BS);
 	void setMove(bool ongoing);