From 45e0d2f663940982df5c2ca47772a6b3e0fc4d7a Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Mon, 29 Apr 2019 21:05:37 +0300 Subject: [PATCH] (99e6eb7c7) Fixed "attempted to access a potentially removed ragdoll" in SoundPlayer.Update, set Character.Controlled to null if the character is removed to prevent this from happening elsewhere --- .../Source/Characters/Character.cs | 3 +-- .../Source/Sounds/SoundPlayer.cs | 2 +- .../Source/Characters/Character.cs | 18 ++++++++++++------ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Characters/Character.cs b/Barotrauma/BarotraumaClient/Source/Characters/Character.cs index 2eff39aa6..b4e831e77 100644 --- a/Barotrauma/BarotraumaClient/Source/Characters/Character.cs +++ b/Barotrauma/BarotraumaClient/Source/Characters/Character.cs @@ -46,8 +46,7 @@ namespace Barotrauma if (controlled == value) return; controlled = value; if (controlled != null) controlled.Enabled = true; - CharacterHealth.OpenHealthWindow = null; - + CharacterHealth.OpenHealthWindow = null; } } diff --git a/Barotrauma/BarotraumaClient/Source/Sounds/SoundPlayer.cs b/Barotrauma/BarotraumaClient/Source/Sounds/SoundPlayer.cs index 3c1705000..515bc987a 100644 --- a/Barotrauma/BarotraumaClient/Source/Sounds/SoundPlayer.cs +++ b/Barotrauma/BarotraumaClient/Source/Sounds/SoundPlayer.cs @@ -238,7 +238,7 @@ namespace Barotrauma } float ambienceVolume = 0.8f; - if (Character.Controlled != null) + if (Character.Controlled != null && !Character.Controlled.Removed) { AnimController animController = Character.Controlled.AnimController; if (animController.HeadInWater) diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs index acf97f741..96bca340e 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs @@ -2534,7 +2534,7 @@ namespace Barotrauma GameMain.GameSession.ReviveCharacter(this); } } - + public override void Remove() { if (Removed) @@ -2546,10 +2546,14 @@ namespace Barotrauma base.Remove(); - if (selectedItems[0] != null) selectedItems[0].Drop(this); - if (selectedItems[1] != null) selectedItems[1].Drop(this); + if (selectedItems[0] != null) { selectedItems[0].Drop(this); } + if (selectedItems[1] != null) { selectedItems[1].Drop(this); } - if (info != null) info.Remove(); + if (info != null) { info.Remove(); } + +#if CLIENT + GameMain.GameSession?.CrewManager?.RemoveCharacter(this); +#endif #if CLIENT GameMain.GameSession?.CrewManager?.RemoveCharacter(this); @@ -2557,6 +2561,8 @@ namespace Barotrauma CharacterList.Remove(this); + if (Controlled == this) { Controlled = null; } + if (Inventory != null) { foreach (Item item in Inventory.Items) @@ -2576,8 +2582,8 @@ namespace Barotrauma foreach (Character c in CharacterList) { - if (c.focusedCharacter == this) c.focusedCharacter = null; - if (c.SelectedCharacter == this) c.SelectedCharacter = null; + if (c.focusedCharacter == this) { c.focusedCharacter = null; } + if (c.SelectedCharacter == this) { c.SelectedCharacter = null; } } } partial void DisposeProjSpecific();