Bunch of fixes to null reference exceptions caused by removing characters mid-round
This commit is contained in:
@@ -11,7 +11,11 @@ namespace Barotrauma
|
||||
|
||||
public static List<AITarget> List = new List<AITarget>();
|
||||
|
||||
public readonly Entity Entity;
|
||||
public Entity Entity
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
private float soundRange;
|
||||
private float sightRange;
|
||||
@@ -47,6 +51,7 @@ namespace Barotrauma
|
||||
public void Remove()
|
||||
{
|
||||
List.Remove(this);
|
||||
Entity = null;
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch)
|
||||
|
||||
@@ -1513,22 +1513,28 @@ namespace Barotrauma
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
foreach (Limb l in Limbs)
|
||||
if (Limbs != null)
|
||||
{
|
||||
l.Remove();
|
||||
foreach (Limb l in Limbs)
|
||||
{
|
||||
l.Remove();
|
||||
}
|
||||
Limbs = null;
|
||||
}
|
||||
Limbs = null;
|
||||
|
||||
foreach (PhysicsBody b in collider)
|
||||
{
|
||||
b.Remove();
|
||||
}
|
||||
|
||||
foreach (RevoluteJoint joint in LimbJoints)
|
||||
if (LimbJoints != null)
|
||||
{
|
||||
GameMain.World.RemoveJoint(joint);
|
||||
foreach (RevoluteJoint joint in LimbJoints)
|
||||
{
|
||||
GameMain.World.RemoveJoint(joint);
|
||||
}
|
||||
LimbJoints = null;
|
||||
}
|
||||
LimbJoints = null;
|
||||
|
||||
list.Remove(this);
|
||||
}
|
||||
|
||||
@@ -1959,6 +1959,13 @@ namespace Barotrauma
|
||||
|
||||
public override void Remove()
|
||||
{
|
||||
#if DEBUG
|
||||
if (Removed)
|
||||
{
|
||||
DebugConsole.ThrowError("Attempting to remove an already removed character\n" + Environment.StackTrace);
|
||||
}
|
||||
#endif
|
||||
|
||||
base.Remove();
|
||||
|
||||
if (info != null) info.Remove();
|
||||
@@ -1969,7 +1976,7 @@ namespace Barotrauma
|
||||
|
||||
if (GameMain.Client != null && GameMain.Client.Character == this) GameMain.Client.Character = null;
|
||||
|
||||
if (aiTarget != null) aiTarget.Remove();
|
||||
if (aiTarget != null) aiTarget.Remove();
|
||||
|
||||
if (AnimController != null) AnimController.Remove();
|
||||
|
||||
|
||||
@@ -109,6 +109,7 @@ namespace Barotrauma
|
||||
public void AddToRemoveQueue(Entity entity)
|
||||
{
|
||||
if (GameMain.Client != null) return;
|
||||
if (removeQueue.Contains(entity) || entity.Removed) return;
|
||||
|
||||
removeQueue.Enqueue(entity);
|
||||
}
|
||||
@@ -116,6 +117,7 @@ namespace Barotrauma
|
||||
public void AddToRemoveQueue(Item item)
|
||||
{
|
||||
if (GameMain.Client != null) return;
|
||||
if (removeQueue.Contains(item) || item.Removed) return;
|
||||
|
||||
removeQueue.Enqueue(item);
|
||||
if (item.ContainedItems == null) return;
|
||||
|
||||
Reference in New Issue
Block a user