From fffc252cb69c5d7647eba0ae922a2a0db7ab6675 Mon Sep 17 00:00:00 2001 From: ottelo <33122175+ottelo9@users.noreply.github.com> Date: Sun, 27 Oct 2024 20:23:49 +0100 Subject: [PATCH] Game crash bugfix McvManagerBotModule.cs Bugfix in McvManagerBotModule.cs. Game can crash at start if you play against lot of AI Exception of type `System.NullReferenceException`: Object reference not set to an instance of an object. --- .../Traits/BotModules/McvManagerBotModule.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs index 64df7d9d66be..644c9670a3e1 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs @@ -58,6 +58,10 @@ public CPos GetBaseCenter(bool random = false) var randomBotCYard = constructionYards.Actors. RandomOrDefault(world.LocalRandom); + //important! Otherwise game can crash at the beginning of a skirmish vs lot of AI + if (randomBotCYard == null) + return CPos.Zero; + var newBaseCenterLocation = world.Map.FindTilesInAnnulus(randomBotCYard.Location, Info.MaxBaseRadius, world.Map.Grid.MaximumTileSearchRange) .Where(a => resourceLayer.GetResource(a).Type != null) @@ -76,7 +80,7 @@ public CPos GetBaseCenter(bool random = false) IBotRequestUnitProduction[] requestUnitProduction; IResourceLayer resourceLayer; CPos initialBaseCenter; - int scanInterval; + int scanInterval=20; bool firstTick = true; public McvManagerBotModule(Actor self, McvManagerBotModuleInfo info) @@ -116,8 +120,7 @@ void IBotTick.BotTick(IBot bot) DeployMcvs(bot, false); firstTick = false; } - - if (--scanInterval <= 0) + else if (--scanInterval <= 0) { scanInterval = Info.ScanForNewMcvInterval; DeployMcvs(bot, true);