From bd651c36049307bc1a37490feff952c8cd7c9ecd Mon Sep 17 00:00:00 2001 From: Erin Catto Date: Thu, 29 Oct 2026 23:17:44 -0700 Subject: [PATCH] save arena space --- src/mesh_contact.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/mesh_contact.c b/src/mesh_contact.c index dab5bbb..0bcbc5b 100644 --- a/src/mesh_contact.c +++ b/src/mesh_contact.c @@ -557,15 +557,6 @@ bool b3ComputeMeshManifolds( b3World* world, int workerIndex, b3Contact* contact float restOffset = B3_MESH_REST_OFFSET; bool enableSpeculative = contact->flags & b3_enableSpeculativePoints; - // Make room for clip points - int pointBufferCapacity = B3_MAX_POINTS_PER_TRIANGLE * triangleCount; - - b3LocalManifoldPoint* pointBuffer = b3Bump( &arena, pointBufferCapacity * sizeof( b3LocalManifoldPoint ) ); - int totalPointCount = 0; - - b3LocalManifold* manifoldBuffer = b3Bump( &arena, triangleCount * sizeof( b3LocalManifold ) ); - int manifoldCount = 0; - b3TriangleCache* triangleCaches = meshContact->triangleCache.data; const b3HullData* hullB = shapeB->type == b3_hullShape ? shapeB->hull : NULL; @@ -702,6 +693,15 @@ bool b3ComputeMeshManifolds( b3World* world, int workerIndex, b3Contact* contact } } + // Make room for clip points. Additional capacity for a heavy clip. + int pointBufferCapacity = B3_MAX_POINTS_PER_TRIANGLE * survivorCount + 2 * B3_MAX_CLIP_POINTS; + + b3LocalManifoldPoint* pointBuffer = b3Bump( &arena, pointBufferCapacity * sizeof( b3LocalManifoldPoint ) ); + int totalPointCount = 0; + + b3LocalManifold* manifoldBuffer = b3Bump( &arena, survivorCount * sizeof( b3LocalManifold ) ); + int manifoldCount = 0; + for ( int survivorIndex = 0; survivorIndex < survivorCount && totalPointCount + 3 < pointBufferCapacity; ++survivorIndex ) { int index = survivorIndices[survivorIndex];