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,7 +125,9 @@ namespace MoonWorks.Collision.Fixed
/// </summary>
public void Remove(T id)
{
var (shape, transform, collisionGroups) = IDLookup[id];
if (IDLookup.TryGetValue(id, out var data))
{
var (shape, transform, collisionGroups) = data;
var box = AABB2D.Transformed(shape.AABB, transform);
var minHash = Hash(box.Min);
@ -141,6 +143,7 @@ namespace MoonWorks.Collision.Fixed
IDLookup.Remove(id);
}
}
/// <summary>
/// Removes everything that has been inserted into the SpatialHash.