Entity removal fixes

This commit is contained in:
Regalis
2016-11-14 17:52:26 +02:00
parent b86231170f
commit 335bf00890
5 changed files with 44 additions and 7 deletions
@@ -1155,11 +1155,22 @@ namespace Barotrauma
public void Remove() public void Remove()
{ {
foreach (Limb l in Limbs) l.Remove(); foreach (Limb l in Limbs)
{
l.Remove();
}
Limbs = null;
collider.Remove();
collider = null;
foreach (RevoluteJoint joint in limbJoints) foreach (RevoluteJoint joint in limbJoints)
{ {
GameMain.World.RemoveJoint(joint); GameMain.World.RemoveJoint(joint);
} }
limbJoints = null;
list.Remove(this);
} }
} }
@@ -2142,6 +2142,8 @@ namespace Barotrauma
if (aiTarget != null) aiTarget.Remove(); if (aiTarget != null) aiTarget.Remove();
if (Lights.LightManager.ViewTarget == this) Lights.LightManager.ViewTarget = null;
if (AnimController!=null) AnimController.Remove(); if (AnimController!=null) AnimController.Remove();
} }
+21 -4
View File
@@ -557,12 +557,29 @@ namespace Barotrauma
public void Remove() public void Remove()
{ {
sprite.Remove(); sprite.Remove();
if (LightSource != null) LightSource.Remove(); sprite = null;
if (damagedSprite != null) damagedSprite.Remove();
body.Remove(); if (LightSource != null)
{
LightSource.Remove();
}
if (damagedSprite != null)
{
damagedSprite.Remove();
damagedSprite = null;
}
if (hitSound != null) hitSound.Remove(); if (body != null)
{
body.Remove();
body = null;
}
if (hitSound != null)
{
hitSound.Remove();
hitSound = null;
}
} }
} }
} }
+8 -1
View File
@@ -133,7 +133,14 @@ namespace Barotrauma
List<Entity> list = new List<Entity>(dictionary.Values); List<Entity> list = new List<Entity>(dictionary.Values);
foreach (Entity e in list) foreach (Entity e in list)
{ {
e.Remove(); try
{
e.Remove();
}
catch (Exception exception)
{
DebugConsole.ThrowError("Error while removing entity \"" + e.ToString() + "\"", exception);
}
} }
dictionary.Clear(); dictionary.Clear();
} }
+1 -1
View File
@@ -334,7 +334,7 @@ namespace Barotrauma
base.Remove(); base.Remove();
hullList.Remove(this); hullList.Remove(this);
if (Submarine == null || !Submarine.Loading) if (Submarine == null || (!Submarine.Loading && !Submarine.Unloading))
{ {
Item.UpdateHulls(); Item.UpdateHulls();
Gap.UpdateHulls(); Gap.UpdateHulls();