From a25750f62d8a638751941d758ee3ee434c4b5a27 Mon Sep 17 00:00:00 2001 From: Vantha Date: Wed, 1 Oct 2025 12:14:11 +0200 Subject: [PATCH] Fix a crash when the Petrabot region analysis fails When the region analysis fails, that's usually because the AI doesn't have any units or CCs at all. Previously, the whole game crashed when serializing because this.noBase was still undefined. --- .../public/simulation/ai/petra/basesManager.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/binaries/data/mods/public/simulation/ai/petra/basesManager.js b/binaries/data/mods/public/simulation/ai/petra/basesManager.js index ce371a3200..dfd0c044c4 100644 --- a/binaries/data/mods/public/simulation/ai/petra/basesManager.js +++ b/binaries/data/mods/public/simulation/ai/petra/basesManager.js @@ -788,7 +788,8 @@ BasesManager.prototype.Serialize = function() return { "properties": properties, - "noBase": this.noBase.Serialize(), + // noBase can be undefined if the region analysis failed and the managers haven't been initialised. + "noBase": this.noBase?.Serialize(), "baseManagers": baseManagers }; }; @@ -798,10 +799,13 @@ BasesManager.prototype.Deserialize = function(gameState, data) for (const key in data.properties) this[key] = data.properties[key]; - this.noBase = new BaseManager(gameState, this); - this.noBase.Deserialize(gameState, data.noBase); - this.noBase.init(gameState, BaseManager.STATE_WITH_ANCHOR); - this.noBase.Deserialize(gameState, data.noBase); + if (data.noBase) + { + this.noBase = new BaseManager(gameState, this); + this.noBase.Deserialize(gameState, data.noBase); + this.noBase.init(gameState, BaseManager.STATE_WITH_ANCHOR); + this.noBase.Deserialize(gameState, data.noBase); + } this.baseManagers = []; for (const basedata of data.baseManagers)