diff --git a/include/box3d/box3d.h b/include/box3d/box3d.h index 1b70d4d..fcfcf54 100644 --- a/include/box3d/box3d.h +++ b/include/box3d/box3d.h @@ -116,8 +116,9 @@ B3_API b3TreeStats b3World_CastShape( b3WorldId worldId, b3Pos origin, const b3S b3QueryFilter filter, b3CastResultFcn* fcn, void* context ); /// Overlap test for all shapes that *potentially* overlap the provided AABB. This only considers static bodies, -/// so it may be invoked concurrently with b3World_Step. This is not thread-safe with shape creation or destruction. -/// This is a workaround for The Legend of California and may be removed later if the workaround is no longer needed. +/// so it may be invoked concurrently with b3World_Step. This is not thread-safe with creationg and destruction +/// operations. This is a workaround for The Legend of California and may be removed later if the workaround is no +/// longer needed. This is not part of a strategy to make concurrent queries thread-safe. B3_API b3TreeStats b3World_OverlapAABB_Static( b3WorldId worldId, b3AABB aabb, b3QueryFilter filter, b3OverlapResultFcn* fcn, void* context ); diff --git a/shared/benchmarks.c b/shared/benchmarks.c index 259160a..bed4079 100644 --- a/shared/benchmarks.c +++ b/shared/benchmarks.c @@ -704,7 +704,6 @@ static void CreateTrees( b3WorldId worldId, int scale, bool useHeightField ) bodyDef.position = (b3Pos){ corner.x, corner.y, corner.z }; } b3BodyId groundId = b3CreateBody( worldId, &bodyDef ); - bodyDef.position = (b3Pos){ 0.0f, 0.0f, 0.0f }; b3ShapeDef shapeDef = b3DefaultShapeDef(); diff --git a/src/solver_set.c b/src/solver_set.c index 1613904..ff0ec53 100644 --- a/src/solver_set.c +++ b/src/solver_set.c @@ -203,9 +203,8 @@ void b3TrySleepIsland( b3World* world, int islandId ) b3SolverSet* sleepSet = b3GetSolverSet( world, sleepSetId ); *sleepSet = (b3SolverSet){ 0 }; - // grab awake set after creating the sleep set because the solver set array may have been resized - b3SolverSet* awakeSet = b3GetSolverSet( world, b3_awakeSet ); - b3SolverSet* disabledSet = b3GetSolverSet( world, b3_disabledSet ); + b3SolverSet* awakeSet = b3GetFixedSolverSet( world, b3_awakeSet ); + b3SolverSet* disabledSet = b3GetFixedSolverSet( world, b3_disabledSet ); B3_ASSERT( 0 <= island->localIndex && island->localIndex < awakeSet->islandSims.count ); sleepSet->setIndex = sleepSetId; diff --git a/test/test_world.c b/test/test_world.c index dd46376..a498e68 100644 --- a/test/test_world.c +++ b/test/test_world.c @@ -1917,9 +1917,10 @@ static void StaticQueryThread( void* context ) StaticQueryHits hits = { shared->worldId, 0, false }; b3World_OverlapAABB_Static( shared->worldId, box, filter, StaticQueryFcn, &hits ); + bool castsPassed = CheckStaticQueries( shared->worldId, expected ); b3AtomicFetchAddInt( &shared->queryCount, 1 ); - if ( hits.count != expected || hits.nonStatic || CheckStaticQueries( shared->worldId, expected ) == false ) + if ( hits.count != expected || hits.nonStatic || castsPassed == false ) { b3AtomicFetchAddInt( &shared->failCount, 1 ); } @@ -1958,8 +1959,12 @@ static int TestOverlapStaticDuringStep( void ) b3CreateHullShape( bodyId, &shapeDef, &cube.base ); } - // Islands falling asleep during the step grow the solver set array under the reader - int setCapacity = b3GetWorldFromId( worldId )->sleepingSets.capacity; + b3World* world = b3GetWorldFromId( worldId ); + + // Islands falling asleep during the step grow the solver set array under the reader. Count the + // steps where that happened while at least two full query rounds, which read static transforms, + // ran inside the step. + int overlappedGrowthCount = 0; StaticQueryShared shared = { 0 }; shared.worldId = worldId; @@ -1977,6 +1982,9 @@ static int TestOverlapStaticDuringStep( void ) ENSURE( b3HasTreeMoved( b3GetWorldFromId( worldId )->broadPhase.trees + b3_staticBody ) ); + int setCapacity = world->sleepingSets.capacity; + int queryCount = b3AtomicLoadInt( &shared.queryCount ); + b3AtomicStoreInt( &shared.expectedCount, staticCount ); b3AtomicStoreInt( &shared.stepping, 1 ); @@ -1989,6 +1997,11 @@ static int TestOverlapStaticDuringStep( void ) b3Yield(); } + if ( world->sleepingSets.capacity > setCapacity && b3AtomicLoadInt( &shared.queryCount ) - queryCount >= 2 ) + { + overlappedGrowthCount += 1; + } + ENSURE( b3HasTreeMoved( b3GetWorldFromId( worldId )->broadPhase.trees + b3_staticBody ) == false ); } @@ -1997,7 +2010,7 @@ static int TestOverlapStaticDuringStep( void ) ENSURE( b3AtomicLoadInt( &shared.queryCount ) > 0 ); ENSURE( b3AtomicLoadInt( &shared.failCount ) == 0 ); - ENSURE( b3GetWorldFromId( worldId )->sleepingSets.capacity > setCapacity ); + ENSURE( overlappedGrowthCount > 0 ); // The serial path agrees with the regular overlap filtered to static bodies. StaticQueryHits hits = { worldId, 0, false };