Manifold allocation cap (#227)

Degenerate scenarios can lead to a huge number of manifolds per contact.
This creates memory and performance problems. So I'm capping them to 8
using cheap heuristics for culling.
This commit is contained in:
Erin Catto 2026-11-17 13:51:59 -08:00 • committed by GitHub
commit 8f3b2e12eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 1161 additions and 138 deletions

View file

@ -14,9 +14,9 @@ B3_API void b3SetLengthUnitsPerMeter( float lengthUnits );
/// Get the current length units per meter.
B3_API float b3GetLengthUnitsPerMeter( void );
// Used to detect bad values. In float mode positions greater than about 16km have precision
// problems, so 100km is a safe limit. Large world mode keeps coordinates accurate much farther
// from the origin, so the sanity limit widens to keep valid far-field positions from tripping it.
/// Used to detect bad values. In float mode positions greater than about 16km have precision
/// problems, so 100km is a safe limit. Large world mode keeps coordinates accurate much farther
/// from the origin, so the sanity limit widens to keep valid far-field positions from tripping it.
#if defined( BOX3D_DOUBLE_PRECISION )
#define B3_HUGE ( 1.0e9f * b3GetLengthUnitsPerMeter() )
#else
@ -32,18 +32,19 @@ B3_API float b3GetLengthUnitsPerMeter( void );
/// size array for Box3D task, which may help with creating stable user task pointers.
#define B3_MAX_TASKS 256
// Maximum number of colors in the constraint graph. Constraints that cannot
// find a color are added to the overflow set which are solved single-threaded.
// The compound barrel benchmark has minor overflow with 24 colors
/// Maximum number of colors in the constraint graph. Constraints that cannot
/// find a color are added to the overflow set which are solved single-threaded.
/// The compound barrel benchmark has minor overflow with 24 colors
#define B3_GRAPH_COLOR_COUNT 24
// Number of contact point buckets for counting the number of contact points per
// shape contact pair. This is just for reporting and doesn't affect simulation.
#define B3_CONTACT_MANIFOLD_COUNT_BUCKETS 8
/// The maximum number of contact manifolds between shape pairs. Excess manifolds are dropped using heuristics until
/// this number is reached. Culling can lead to contact dither across time steps. Contact recycling mitigates the
/// dithering.
#define B3_MAX_MANIFOLDS 8
// A small length used as a collision and constraint tolerance. Usually it is
// chosen to be numerically significant, but visually insignificant. In meters.
// @warning modifying this can have a significant impact on stability
/// A small length used as a collision and constraint tolerance. Usually it is
/// chosen to be numerically significant, but visually insignificant. In meters.
/// @warning modifying this can have a significant impact on stability
#define B3_LINEAR_SLOP ( 0.005f * b3GetLengthUnitsPerMeter() )
/// The minimum length of a capsules. Very short capsules should be created as spheres

View file

@ -573,50 +573,50 @@ B3_API b3ShapeDef b3DefaultShapeDef( void );
/// @ingroup world
typedef struct b3Profile
{
float step; //
float pairs; //
float collide; //
float solve; //
float solverSetup; //
float constraints; //
float prepareConstraints; //
float integrateVelocities; //
float warmStart; //
float solveImpulses; //
float integratePositions; //
float relaxImpulses; //
float restitution; //
float storeImpulses; //
float splitIslands; //
float transforms; //
float sensorHits; //
float jointEvents; //
float hitEvents; //
float refit; //
float bullets; //
float sleepIslands; //
float sensors; //
float step; ///<
float pairs; ///<
float collide; ///<
float solve; ///<
float solverSetup; ///<
float constraints; ///<
float prepareConstraints; ///<
float integrateVelocities; ///<
float warmStart; ///<
float solveImpulses; ///<
float integratePositions; ///<
float relaxImpulses; ///<
float restitution; ///<
float storeImpulses; ///<
float splitIslands; ///<
float transforms; ///<
float sensorHits; ///<
float jointEvents; ///<
float hitEvents; ///<
float refit; ///<
float bullets; ///<
float sleepIslands; ///<
float sensors; ///<
} b3Profile;
/// Counters that give details of the simulation size.
/// @ingroup world
typedef struct b3Counters
{
int64_t byteCount; //
int bodyCount; //
int shapeCount; //
int contactCount; //
int jointCount; //
int islandCount; //
int stackUsed; //
int arenaCapacity; //
int staticTreeHeight; //
int treeHeight; //
int satCallCount; //
int satCacheHitCount; //
int taskCount; //
int colorCounts[24]; //
int manifoldCounts[B3_CONTACT_MANIFOLD_COUNT_BUCKETS]; //
int64_t byteCount; ///<
int bodyCount; ///<
int shapeCount; ///<
int contactCount; ///<
int jointCount; ///<
int islandCount; ///<
int stackUsed; ///<
int arenaCapacity; ///<
int staticTreeHeight; ///<
int treeHeight; ///<
int satCallCount; ///<
int satCacheHitCount; ///<
int taskCount; ///<
int colorCounts[24]; ///<
int manifoldCounts[B3_MAX_MANIFOLDS]; ///<
/// Number of contacts touched by the collide pass
/// graph contacts + awake-set non-touching