{"record":{"id":"29b0b1922971e46e","repo":"stride3d/stride","slug":"this-manifold-is-empty","errorCode":null,"errorMessage":"This manifold is empty","messagePattern":"This manifold is empty","errorType":"exception","errorClass":"IndexOutOfRangeException","httpStatus":null,"severity":"warning","filePath":"sources/engine/Stride.BepuPhysics/Stride.BepuPhysics/Definitions/Contacts/ContactEventsManager.cs","lineNumber":473,"sourceCode":"            }\n\n            return false;\n        }\n    }\n\n    [Flags]\n    private enum Events\n    {\n        TouchingA = 0b01,\n        TouchingB = 0b10,\n    }\n\n\n    private struct EmptyManifold : IContactManifold<EmptyManifold>\n    {\n        public int Count => 0;\n        public bool Convex => true;\n        public Contact this[int contactIndex] { get => throw new IndexOutOfRangeException(\"This manifold is empty\"); set => throw new IndexOutOfRangeException(\"This manifold is empty\"); }\n        public static ref ConvexContact GetConvexContactReference(ref EmptyManifold manifold, int contactIndex) => throw new IndexOutOfRangeException(\"This manifold is empty\");\n        public static ref float GetDepthReference(ref EmptyManifold manifold, int contactIndex) => throw new IndexOutOfRangeException(\"This manifold is empty\");\n        public static ref int GetFeatureIdReference(ref EmptyManifold manifold, int contactIndex) => throw new IndexOutOfRangeException(\"This manifold is empty\");\n        public static ref Contact GetNonconvexContactReference(ref EmptyManifold manifold, int contactIndex) => throw new IndexOutOfRangeException(\"This manifold is empty\");\n        public static ref Vector3 GetNormalReference(ref EmptyManifold manifold, int contactIndex) => throw new IndexOutOfRangeException(\"This manifold is empty\");\n        public static ref Vector3 GetOffsetReference(ref EmptyManifold manifold, int contactIndex) => throw new IndexOutOfRangeException(\"This manifold is empty\");\n        public void GetContact(int contactIndex, out Vector3 offset, out Vector3 normal, out float depth, out int featureId) => throw new IndexOutOfRangeException(\"This manifold is empty\");\n        public void GetContact(int contactIndex, out Contact contactData) => throw new IndexOutOfRangeException(\"This manifold is empty\");\n        public float GetDepth(int contactIndex) => throw new IndexOutOfRangeException(\"This manifold is empty\");\n        public int GetFeatureId(int contactIndex) => throw new IndexOutOfRangeException(\"This manifold is empty\");\n        public Vector3 GetNormal(int contactIndex) => throw new IndexOutOfRangeException(\"This manifold is empty\");\n        public Vector3 GetOffset(int contactIndex) => throw new IndexOutOfRangeException(\"This manifold is empty\");\n    }\n}\n\ninternal readonly record struct OrderedPair\n{\n    public readonly CollidableComponent A, B;","sourceCodeStart":455,"sourceCodeEnd":491,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.BepuPhysics/Stride.BepuPhysics/Definitions/Contacts/ContactEventsManager.cs#L455-L491","documentation":"EmptyManifold is a sentinel IContactManifold with zero contacts used by ContactEventsManager to represent manifolds with no contact points. Any attempt to index into it — here the Contact this[int] getter — has no contact to return and throws IndexOutOfRangeException('This manifold is empty').","triggerScenarios":"Accessing the indexer of an EmptyManifold (e.g. manifold[0]) — iterating contact points of a manifold whose Count is 0 without checking Count first.","commonSituations":"Contact-event handler code that loops a fixed number of contacts instead of looping to manifold.Count; reading contact data when a pair stopped touching (manifold cleared to the empty sentinel).","solutions":["Check manifold.Count > 0 before reading any contact.","Loop with for (int i = 0; i < manifold.Count; i++) instead of a fixed range.","Handle the empty case as 'no contacts / stopped touching' in your contact event handler."],"exampleFix":"// before\nvar contact = manifold[0];\n// after\nif (manifold.Count > 0)\n{\n    var contact = manifold[0];\n}","handlingStrategy":"validation","validationCode":"if (manifold.Count > 0)\n{\n    var contact = manifold[0];\n}","typeGuard":"static bool TryGetContact(IContactManifold m, int i, out Contact c) { if (i < m.Count) { c = m[i]; return true; } c = default; return false; }","tryCatchPattern":"try { var c = manifold[0]; } catch (IndexOutOfRangeException) { /* empty manifold: no contacts */ }","preventionTips":["Always bound per-contact access by manifold.Count","Treat Count == 0 as 'pair not touching' in contact handlers","Never use hard-coded contact indices"],"tags":["physics","collision","index-out-of-range"],"backgroundTag":"index-out-of-range","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}