Fix crash when creating cloth with all vertices fixed

This commit is contained in:
2023-07-14 14:12:30 +02:00
parent 3141b4fb04
commit 3f9e286279
2 changed files with 15 additions and 5 deletions
+10
View File
@@ -507,6 +507,16 @@ bool Cloth::CreateCloth()
#if WITH_CLOTH
PROFILE_CPU();
// Skip if all vertices are fixed so cloth sim doesn't make sense
if (_paint.HasItems())
{
bool allZero = true;
for (int32 i = 0; i < _paint.Count() && allZero; i++)
allZero = _paint[i] <= ZeroTolerance;
if (allZero)
return false;
}
// Get mesh data
// TODO: consider making it via async task so physics can wait on the cloth setup from mesh data just before next fixed update which gives more time when loading scene
const ModelInstanceActor::MeshReference mesh = GetMesh();
@@ -3332,21 +3332,21 @@ void* PhysicsBackend::CreateCloth(const PhysicsClothDesc& desc)
{
// Sanity check
bool allValid = true;
for (int32 i = 0; i < desc.VerticesCount; i++)
for (uint32 i = 0; i < desc.VerticesCount; i++)
allValid &= !(*(Float3*)((byte*)desc.VerticesData + i * desc.VerticesStride)).IsNanOrInfinity();
if (desc.InvMassesData)
{
for (int32 i = 0; i < desc.VerticesCount; i++)
for (uint32 i = 0; i < desc.VerticesCount; i++)
{
float v = *(float*)((byte*)desc.InvMassesData + i * desc.InvMassesStride);
const float v = *(float*)((byte*)desc.InvMassesData + i * desc.InvMassesStride);
allValid &= !isnan(v) && !isinf(v);
}
}
if (desc.MaxDistancesData)
{
for (int32 i = 0; i < desc.VerticesCount; i++)
for (uint32 i = 0; i < desc.VerticesCount; i++)
{
float v = *(float*)((byte*)desc.MaxDistancesData + i * desc.MaxDistancesStride);
const float v = *(float*)((byte*)desc.MaxDistancesData + i * desc.MaxDistancesStride);
allValid &= !isnan(v) && !isinf(v);
}
}