Fixed crash on some Entity removals

This commit is contained in:
Matt Thorson
2020-05-30 16:19:46 -07:00
parent 4daafca0b7
commit 9bb6ac6a73
3 changed files with 17 additions and 22 deletions

View File

@ -29,12 +29,12 @@ namespace Strawberry
delete c;
}
public void Added(Scene scene)
private void Added(Scene scene)
{
Scene = scene;
}
public void Removed()
private void Removed()
{
Scene = null;
}
@ -81,7 +81,7 @@ namespace Strawberry
return component;
}
public void UpdateLists()
private void UpdateLists()
{
if (toRemove.Count > 0)
{
@ -425,10 +425,5 @@ namespace Strawberry
{
Draw.Rect(SceneHitbox, color);
}
static public int operator<=>(Entity a, Entity b)
{
return a.Depth <=> b.Depth;
}
}
}

View File

@ -65,14 +65,14 @@ namespace Strawberry
public virtual void Update()
{
UpdateLists();
for (var e in entities)
for (let e in entities)
if (e.Active)
e.Update();
}
public virtual void Draw()
{
for (var e in entities)
for (let e in entities)
if (e.Visible)
e.Draw();
}
@ -95,11 +95,13 @@ namespace Strawberry
{
if (toRemove.Count > 0)
{
for (var e in toRemove)
for (let e in toRemove)
{
Calc.Log(scope => e.GetType().GetName);
entities.Remove(e);
UntrackEntity(e);
e.Removed();
e.[Friend]Removed();
if (e.DeleteOnRemove)
delete e;
}
@ -109,22 +111,21 @@ namespace Strawberry
if (toAdd.Count > 0)
{
for (var e in toAdd)
for (let e in toAdd)
{
entities.Add(e);
TrackEntity(e);
e.Added(this);
e.[Friend]Added(this);
}
}
for (var e in entities)
e.UpdateLists();
for (let e in entities)
e.[Friend]UpdateLists();
if (toAdd.Count > 0)
{
for (var e in toAdd)
for (let e in toAdd)
e.Started();
toAdd.Clear();
}
}