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 static List<AITarget> List = new List<AITarget>();
|
||||||
|
|
||||||
public readonly Entity Entity;
|
public Entity Entity
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
private set;
|
||||||
|
}
|
||||||
|
|
||||||
private float soundRange;
|
private float soundRange;
|
||||||
private float sightRange;
|
private float sightRange;
|
||||||
@@ -47,6 +51,7 @@ namespace Barotrauma
|
|||||||
public void Remove()
|
public void Remove()
|
||||||
{
|
{
|
||||||
List.Remove(this);
|
List.Remove(this);
|
||||||
|
Entity = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw(SpriteBatch spriteBatch)
|
public void Draw(SpriteBatch spriteBatch)
|
||||||
|
|||||||
@@ -1513,22 +1513,28 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public void Remove()
|
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)
|
foreach (PhysicsBody b in collider)
|
||||||
{
|
{
|
||||||
b.Remove();
|
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);
|
list.Remove(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1959,6 +1959,13 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public override void Remove()
|
public override void Remove()
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
if (Removed)
|
||||||
|
{
|
||||||
|
DebugConsole.ThrowError("Attempting to remove an already removed character\n" + Environment.StackTrace);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
base.Remove();
|
base.Remove();
|
||||||
|
|
||||||
if (info != null) info.Remove();
|
if (info != null) info.Remove();
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ namespace Barotrauma
|
|||||||
public void AddToRemoveQueue(Entity entity)
|
public void AddToRemoveQueue(Entity entity)
|
||||||
{
|
{
|
||||||
if (GameMain.Client != null) return;
|
if (GameMain.Client != null) return;
|
||||||
|
if (removeQueue.Contains(entity) || entity.Removed) return;
|
||||||
|
|
||||||
removeQueue.Enqueue(entity);
|
removeQueue.Enqueue(entity);
|
||||||
}
|
}
|
||||||
@@ -116,6 +117,7 @@ namespace Barotrauma
|
|||||||
public void AddToRemoveQueue(Item item)
|
public void AddToRemoveQueue(Item item)
|
||||||
{
|
{
|
||||||
if (GameMain.Client != null) return;
|
if (GameMain.Client != null) return;
|
||||||
|
if (removeQueue.Contains(item) || item.Removed) return;
|
||||||
|
|
||||||
removeQueue.Enqueue(item);
|
removeQueue.Enqueue(item);
|
||||||
if (item.ContainedItems == null) return;
|
if (item.ContainedItems == null) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user