From 3d5d7ad968750fcac5f6471bfd6047dc045faf94 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 17 Jul 2023 15:34:38 +0200 Subject: [PATCH] Don't recook cloth mesh when rebuilding it --- Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp b/Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp index 7815ffd1e..2fb6cc5d6 100644 --- a/Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp +++ b/Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp @@ -1692,7 +1692,16 @@ void PhysicsBackend::EndSimulateScene(void* scene) clothSettings.Actor->OnPostUpdate(); } for (auto cloth : brokenCloths) + { + // Rebuild cloth object but keep fabric ref to prevent fabric recook + auto fabric = &((nv::cloth::Cloth*)cloth->_cloth)->getFabric(); + Fabrics[fabric].Refs++; + fabric->incRefCount(); cloth->Rebuild(); + fabric->decRefCount(); + if (--Fabrics[fabric].Refs == 0) + Fabrics.Remove(fabric); + } } } @@ -3460,6 +3469,7 @@ void* PhysicsBackend::CreateCloth(const PhysicsClothDesc& desc) if (fabric) { Fabrics[fabric].Refs++; + fabric->incRefCount(); } else {