From 8bab09d37c8c1915d77230d0e4f2dd5bf39b9e27 Mon Sep 17 00:00:00 2001 From: wraitii Date: Sat, 19 Jan 2019 07:44:40 +0000 Subject: [PATCH] Fix UnitAI infinite loop following a16e7c0a56 As reported by Angen and Gurken Khan on the forums, there is a crash following a16e7c0a56 caused by an infinite loop in UnitAI. The reason is that IDLE.enter can order us to attack, which can fail, switching us right away back to idle. FinishOrder's behaviour allows us to have IDLE as a default state and lets us not lose a turn when becoming idle, so to keep this behaviour explicitely check that we are not already in IDLE before switching states. Reported by: Angen, Gurken Khan Commented by: elexis, Itms Differential Revision: https://code.wildfiregames.com/D1743 This was SVN commit r22059. --- binaries/data/mods/public/simulation/components/UnitAI.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/binaries/data/mods/public/simulation/components/UnitAI.js b/binaries/data/mods/public/simulation/components/UnitAI.js index cb5dc7b475..0f0a349100 100644 --- a/binaries/data/mods/public/simulation/components/UnitAI.js +++ b/binaries/data/mods/public/simulation/components/UnitAI.js @@ -3536,7 +3536,6 @@ UnitAI.prototype.SetNextState = function(state) this.UnitFsm.SetNextState(this, state); }; - UnitAI.prototype.DeferMessage = function(msg) { this.UnitFsm.DeferMessage(this, msg); @@ -3592,7 +3591,11 @@ UnitAI.prototype.FinishOrder = function() this.orderQueue = []; this.order = undefined; - this.SetNextState("IDLE"); + + // Switch to IDLE as a default state, but only if our current state is not IDLE + // as this can trigger infinite loops by entering IDLE repeatedly. + if (!this.GetCurrentState().endsWith(".IDLE")) + this.SetNextState("IDLE"); Engine.PostMessage(this.entity, MT_UnitAIOrderDataChanged, { "to": this.GetOrderData() });