diff --git a/src/broad_phase.c b/src/broad_phase.c index a14a1a2..058aa79 100644 --- a/src/broad_phase.c +++ b/src/broad_phase.c @@ -403,6 +403,9 @@ void b3UpdateBroadPhasePairs( b3World* world ) if ( moveCount == 0 ) { + // GameCult fork: destroying a proxy unbuffers its move but leaves its ancestors flagged enlarged, so an empty + // move buffer does not mean the trees are clean. The rebuild clears the flags; on a clean tree it is a no-op. + b3UpdateTreesTask( world ); return; } diff --git a/test/test_world.c b/test/test_world.c index 714430f..0517671 100644 --- a/test/test_world.c +++ b/test/test_world.c @@ -1122,6 +1122,47 @@ int ContactFrictionRecycledTest( void ) return 0; } +// GameCult fork. A body whose proxy was enlarged in the last step is destroyed before the next step, and it was +// the only proxy in the move buffer. Its ancestors in the dynamic tree are still flagged enlarged, so the next +// step must still rebuild the tree: with validation on, a skipped rebuild trips ValidateNoEnlarged in the solver. +int DestroyEnlargedProxyTest( void ) +{ + b3WorldDef worldDef = b3DefaultWorldDef(); + worldDef.gravity = b3Vec3_zero; + b3WorldId worldId = b3CreateWorld( &worldDef ); + + b3BodyDef bodyDef = b3DefaultBodyDef(); + bodyDef.type = b3_dynamicBody; + b3ShapeDef shapeDef = b3DefaultShapeDef(); + b3Sphere sphere = { b3Vec3_zero, 0.25f }; + + // Resting bodies far apart: they never leave their fat AABBs, so after the first step only the mover is buffered. + enum + { + e_count = 8 + }; + b3BodyId bodyIds[e_count]; + for ( int i = 0; i < e_count; ++i ) + { + bodyDef.position = (b3Pos){ 4.0f * i, 0.0f, 0.0f }; + bodyIds[i] = b3CreateBody( worldId, &bodyDef ); + b3CreateSphereShape( bodyIds[i], &shapeDef, &sphere ); + } + b3World_Step( worldId, 1.0f / 60.0f, 4 ); + + // Each body in turn is the mover; some lie deep enough that an enlarged ancestor outlives their removal. + for ( int i = 0; i < e_count; ++i ) + { + b3Body_SetLinearVelocity( bodyIds[i], (b3Vec3){ 0.0f, 30.0f, 0.0f } ); + b3World_Step( worldId, 1.0f / 60.0f, 4 ); + b3DestroyBody( bodyIds[i] ); + b3World_Step( worldId, 1.0f / 60.0f, 4 ); + } + + b3DestroyWorld( worldId ); + return 0; +} + int WorldTest( void ) { RUN_SUBTEST( HelloWorld ); @@ -1145,6 +1186,7 @@ int WorldTest( void ) RUN_SUBTEST( TestHullDatabase ); RUN_SUBTEST( ContactFrictionHookTest ); RUN_SUBTEST( ContactFrictionRecycledTest ); + RUN_SUBTEST( DestroyEnlargedProxyTest ); return 0; }