This function in BoundingVolumeUtilities.h has a bug:
template<typename ParticleView, typename T, int d>
typename TEnableIf<TModels_V<CParticleView, ParticleView>>::Type ComputeAllWorldSpaceBoundingBoxes(const ParticleView& Particles, const TArray<bool>& RequiresBounds, const bool bUseVelocity, const T Dt, TArray<TAABB<T, d>>& WorldSpaceBoxes)
{
WorldSpaceBoxes.AddUninitialized(Particles.Num());
ParticlesParallelFor(Particles, [&RequiresBounds, &WorldSpaceBoxes, bUseVelocity, Dt](const auto& Particle, int32 Index)
{
if (RequiresBounds[Index])
{
WorldSpaceBoxes[Index] = ComputeWorldSpaceBoundingBox(Particle);
if (bUseVelocity)
{
if (const auto PBDRigid = Particle.AsDynamic())
{
WorldSpaceBoxes.Last().ThickenSymmetrically(ComputeBoundsThickness(*PBDRigid, Dt, 0, 1));
}
}
}
});
}
That final WorldSpaceBoxes.Last() should really be WorldSpaceBoxes[Index]. Notice you’re pre-allocating the array for the ParallelFor. I suspect this is a leftover from when this code wasn’t parallel, and it was adding the boxes sequentially into the array.
Ernesto.