fix spatial hash remove crash if key does not exist

pull/46/head
cosmonaut 2022-12-26 20:03:20 -08:00
parent b81780e258
commit c04d021237
1 changed files with 16 additions and 13 deletions

View File

@ -125,21 +125,24 @@ namespace MoonWorks.Collision.Fixed
/// </summary>
public void Remove(T id)
{
var (shape, transform, collisionGroups) = IDLookup[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 (IDLookup.TryGetValue(id, out var data))
{
if (hashDictionary.ContainsKey(key))
{
hashDictionary[key].Remove(id);
}
}
var (shape, transform, collisionGroups) = data;
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>