Bug in ComputeAllWorldSpaceBoundingBoxes

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.

Hello Ernesto,

Thank you for your report. Are you able to provide a description of the bug and what issues are caused by the current `ComputeAllWorldSpaceBoundingBoxes` implementation? This will assist us in identifying if it is necessary to put together a bug report for this. Thank you!

Take care,

John

I’m picking up this case where John left off, sorry for the delay. Confirming the bug with the Chaos team.

Yep, confirmed and your suggestion is correct. Merged in with CL 46769819 on //UE5/Main. Thanks for reporting this!

Hi John.

Unfortunately I don’t have a repro case at hand. I was tracking down the usage of ParticlesParallelFor() and spotted this bug.

The net effect of the bug is that anything that calls this function with bUseVelocity = true will not apply the ThickenSimmetrically() to the bounds of the particle, with the exception of the very last particle.

Ernesto.