fix spatial hash remove crash if key does not exist

cosmonaut 2022-12-26 20:03:20 -08:00
parent 74f729dcb9
commit 5223e92aa8
1 changed files with 16 additions and 13 deletions

View File

@ -125,21 +125,24 @@ namespace MoonWorks.Collision.Fixed
/// </summary> /// </summary>
public void Remove(T id) public void Remove(T id)
{ {
var (shape, transform, collisionGroups) = IDLookup[id]; if (IDLookup.TryGetValue(id, out var data))
var box = AABB2D.Transformed(shape.AABB, transform);
var minHash = Hash(box.Min);
var maxHash = Hash(box.Max);
foreach (var key in Keys(minHash.Item1, minHash.Item2, maxHash.Item1, maxHash.Item2))
{ {
if (hashDictionary.ContainsKey(key)) var (shape, transform, collisionGroups) = data;
{
hashDictionary[key].Remove(id);
}
}
IDLookup.Remove(id); var box = AABB2D.Transformed(shape.AABB, transform);
var minHash = Hash(box.Min);
var maxHash = Hash(box.Max);
foreach (var key in Keys(minHash.Item1, minHash.Item2, maxHash.Item1, maxHash.Item2))
{
if (hashDictionary.ContainsKey(key))
{
hashDictionary[key].Remove(id);
}
}
IDLookup.Remove(id);
}
} }
/// <summary> /// <summary>