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