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()
This commit is contained in:
NotAlwaysTrue
2025-12-22 21:51:07 +08:00
parent 5b823d8684
commit b891ec7793
2 changed files with 14 additions and 9 deletions
@@ -281,6 +281,8 @@ namespace Barotrauma
Item item = new Item(itemPrefab, character.Position, null); Item item = new Item(itemPrefab, character.Position, null);
#if SERVER #if SERVER
if (GameMain.Server != null && Entity.Spawner != null && createNetworkEvents) if (GameMain.Server != null && Entity.Spawner != null && createNetworkEvents)
{
try
{ {
if (GameMain.Server.EntityEventManager.UniqueEvents.ToList().Any(ev => ev.Entity == item)) if (GameMain.Server.EntityEventManager.UniqueEvents.ToList().Any(ev => ev.Entity == item))
{ {
@@ -290,9 +292,12 @@ namespace Barotrauma
GameMain.Server.EntityEventManager.UniqueEvents.RemoveAll(ev => ev.Entity == item); GameMain.Server.EntityEventManager.UniqueEvents.RemoveAll(ev => ev.Entity == item);
GameMain.Server.EntityEventManager.Events.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 #endif
if (itemElement.GetAttributeBool("equip", false)) if (itemElement.GetAttributeBool("equip", false))
{ {
@@ -426,7 +426,7 @@ namespace Barotrauma
if (points[0].Y > Body.SimPosition.Y && if (points[0].Y > Body.SimPosition.Y &&
!Character.CharacterList.Any(c => c.Submarine == otherSubmarine && !c.IsIncapacitated && c.TeamID == otherSubmarine.TeamID)) !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; break;
} }
} }