diff --git a/src/Jitter2/World.Detect.cs b/src/Jitter2/World.Detect.cs index 70b41b7d..2af5b1d0 100644 --- a/src/Jitter2/World.Detect.cs +++ b/src/Jitter2/World.Detect.cs @@ -427,23 +427,24 @@ public void GetArbiter(ulong id0, ulong id1, RigidBody b0, RigidBody b1, out Arb arb = new Arbiter(); } + var h = memContacts.Allocate(true); + arb.Handle = h; + h.Data.Init(b0, b1); + h.Data.Key = arbiterKey; + arb.Body1 = b0; + arb.Body2 = b1; + + Debug.Assert(arb != null && memContacts.IsActive(arb.Handle)); + bool success = arbiters.TryAdd(arbiterKey, arb); if (success) { - var h = memContacts.Allocate(true); - arb.Handle = h; - h.Data.Init(b0, b1); - h.Data.Key = arbiterKey; - arb.Body1 = b0; - arb.Body2 = b1; - - Debug.Assert(arb != null && memContacts.IsActive(arb.Handle)); - deferredArbiters.Add(arb); } else { + memContacts.Free(h); Arbiter.Pool.Push(arb); } }