Fix crash when creating cloth with all vertices fixed
This commit is contained in:
@@ -507,6 +507,16 @@ bool Cloth::CreateCloth()
|
|||||||
#if WITH_CLOTH
|
#if WITH_CLOTH
|
||||||
PROFILE_CPU();
|
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
|
// 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
|
// 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();
|
const ModelInstanceActor::MeshReference mesh = GetMesh();
|
||||||
|
|||||||
@@ -3332,21 +3332,21 @@ void* PhysicsBackend::CreateCloth(const PhysicsClothDesc& desc)
|
|||||||
{
|
{
|
||||||
// Sanity check
|
// Sanity check
|
||||||
bool allValid = true;
|
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();
|
allValid &= !(*(Float3*)((byte*)desc.VerticesData + i * desc.VerticesStride)).IsNanOrInfinity();
|
||||||
if (desc.InvMassesData)
|
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);
|
allValid &= !isnan(v) && !isinf(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (desc.MaxDistancesData)
|
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);
|
allValid &= !isnan(v) && !isinf(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user