Fix crash when creating empty cloth

This commit is contained in:
Wojtek Figat
2023-11-01 10:29:44 +01:00
parent 536be6c6cf
commit 1a254afd4f

View File

@@ -95,14 +95,17 @@ void Cloth::SetFabric(const FabricSettings& value)
void Cloth::Rebuild()
{
#if WITH_CLOTH
// Remove old
if (IsDuringPlay())
PhysicsBackend::RemoveCloth(GetPhysicsScene()->GetPhysicsScene(), _cloth);
DestroyCloth();
if (_cloth)
{
// Remove old
if (IsDuringPlay())
PhysicsBackend::RemoveCloth(GetPhysicsScene()->GetPhysicsScene(), _cloth);
DestroyCloth();
}
// Create new
CreateCloth();
if (IsDuringPlay())
if (IsDuringPlay() && _cloth)
PhysicsBackend::AddCloth(GetPhysicsScene()->GetPhysicsScene(), _cloth);
#endif
}