From 39bfd15aca2374232cb4ff86b0e0a49ec719c157 Mon Sep 17 00:00:00 2001 From: Angen Date: Fri, 31 Jan 2020 20:00:06 +0000 Subject: [PATCH] Fix checks for range existence following 6bc99c47e1 Function introduced in 6bc99c47e1, GetRange can return undefined when required component does not exist. Fixing two oversights, when check is needed. Differential Revision: https://code.wildfiregames.com/D2608 Fixes: #5666 This was SVN commit r23471. --- binaries/data/mods/public/simulation/components/UnitAI.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/binaries/data/mods/public/simulation/components/UnitAI.js b/binaries/data/mods/public/simulation/components/UnitAI.js index 1be662b261..2096f0462d 100644 --- a/binaries/data/mods/public/simulation/components/UnitAI.js +++ b/binaries/data/mods/public/simulation/components/UnitAI.js @@ -4739,6 +4739,8 @@ UnitAI.prototype.FaceTowardsTarget = function(target) UnitAI.prototype.CheckTargetDistanceFromHeldPosition = function(target, iid, type) { let range = this.GetRange(iid, type); + if (!range) + return false; let cmpPosition = Engine.QueryInterface(target, IID_Position); if (!cmpPosition || !cmpPosition.IsInWorld()) @@ -5809,6 +5811,8 @@ UnitAI.prototype.GetQueryRange = function(iid) else if (this.GetStance().respondHoldGround) { let range = this.GetRange(iid); + if (!range) + return ret; ret.max = Math.min(range.max + visionRange / 2, visionRange); } // We probably have stance 'passive' and we wouldn't have a range, @@ -5912,7 +5916,7 @@ UnitAI.prototype.GetRange = function(iid, type) { let component = Engine.QueryInterface(this.entity, iid); if (!component) - return; + return undefined; return component.GetRange(type); }