From b891ec77933ce8f8e2703e282c5752d18c2bfcf5 Mon Sep 17 00:00:00 2001 From: NotAlwaysTrue <2136846186@qq.com> Date: Mon, 22 Dec 2025 21:51:07 +0800 Subject: [PATCH] Add a try-finally in HumanPrefab to fix an issue causing issue(Destination array was not long enough. ) Fixed another Collection was modified in SubmarineBody.Update() --- .../SharedSource/Characters/HumanPrefab.cs | 21 ++++++++++++------- .../SharedSource/Map/SubmarineBody.cs | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Barotrauma/BarotraumaShared/SharedSource/Characters/HumanPrefab.cs b/Barotrauma/BarotraumaShared/SharedSource/Characters/HumanPrefab.cs index 04bb60aa3..816dd61ee 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Characters/HumanPrefab.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Characters/HumanPrefab.cs @@ -282,16 +282,21 @@ namespace Barotrauma #if SERVER if (GameMain.Server != null && Entity.Spawner != null && createNetworkEvents) { - if (GameMain.Server.EntityEventManager.UniqueEvents.ToList().Any(ev => ev.Entity == item)) + try { - string errorMsg = $"Error while spawning job items. Item {item.Name} created network events before the spawn event had been created."; - DebugConsole.ThrowError(errorMsg); - GameAnalyticsManager.AddErrorEventOnce("Job.InitializeJobItem:EventsBeforeSpawning", GameAnalyticsManager.ErrorSeverity.Error, errorMsg); - GameMain.Server.EntityEventManager.UniqueEvents.RemoveAll(ev => ev.Entity == item); - GameMain.Server.EntityEventManager.Events.RemoveAll(ev => ev.Entity == item); + if (GameMain.Server.EntityEventManager.UniqueEvents.ToList().Any(ev => ev.Entity == item)) + { + string errorMsg = $"Error while spawning job items. Item {item.Name} created network events before the spawn event had been created."; + DebugConsole.ThrowError(errorMsg); + GameAnalyticsManager.AddErrorEventOnce("Job.InitializeJobItem:EventsBeforeSpawning", GameAnalyticsManager.ErrorSeverity.Error, errorMsg); + GameMain.Server.EntityEventManager.UniqueEvents.RemoveAll(ev => ev.Entity == item); + GameMain.Server.EntityEventManager.Events.RemoveAll(ev => ev.Entity == item); + } + } + finally + { + Entity.Spawner.CreateNetworkEvent(new EntitySpawner.SpawnEntity(item)); } - - Entity.Spawner.CreateNetworkEvent(new EntitySpawner.SpawnEntity(item)); } #endif if (itemElement.GetAttributeBool("equip", false)) diff --git a/Barotrauma/BarotraumaShared/SharedSource/Map/SubmarineBody.cs b/Barotrauma/BarotraumaShared/SharedSource/Map/SubmarineBody.cs index cf1dec2ef..29254525c 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Map/SubmarineBody.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Map/SubmarineBody.cs @@ -426,7 +426,7 @@ namespace Barotrauma if (points[0].Y > Body.SimPosition.Y && !Character.CharacterList.Any(c => c.Submarine == otherSubmarine && !c.IsIncapacitated && c.TeamID == otherSubmarine.TeamID)) { - otherSubmarine.GetConnectedSubs().ForEach(s => s.SubBody.forceUpwardsTimer += deltaTime); + otherSubmarine.GetConnectedSubs().ToList().ForEach(s => s.SubBody.forceUpwardsTimer += deltaTime); break; } }