1
0
forked from mirrors/0ad

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.
This commit is contained in:
Vantha
2025-10-01 12:14:11 +02:00
committed by Phosit
parent ce512e383f
commit a25750f62d
@@ -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)