From 248aee46f72e5776a325a03b313ed14cc03e0992 Mon Sep 17 00:00:00 2001 From: ss Date: Mon, 26 Jun 2023 13:49:41 +0500 Subject: [PATCH 2/2] threads error --- .../lowlevel/software/include/PxsSimulationController.h | 2 ++ physx/source/lowleveldynamics/src/DyDynamics.cpp | 8 ++++++++ physx/source/simulationcontroller/src/ScScene.cpp | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/physx/source/lowlevel/software/include/PxsSimulationController.h b/physx/source/lowlevel/software/include/PxsSimulationController.h index 670e7a97..202a3e1e 100644 --- a/physx/source/lowlevel/software/include/PxsSimulationController.h +++ b/physx/source/lowlevel/software/include/PxsSimulationController.h @@ -37,6 +37,7 @@ #include "foundation/PxUserAllocated.h" #include "PxScene.h" #include "PxParticleSystem.h" +#include "foundation/PxMutex.h" #if PX_ENABLE_FEATURES_UNDER_CONSTRUCTION #include "PxFLIPParticleSystem.h" @@ -123,6 +124,7 @@ namespace physx class PxsSimulationController : public PxUserAllocated { public: + PxMutex __shapeInterationLock; PxsSimulationController(PxsSimulationControllerCallback* callback): mCallback(callback){} virtual ~PxsSimulationController(){} diff --git a/physx/source/lowleveldynamics/src/DyDynamics.cpp b/physx/source/lowleveldynamics/src/DyDynamics.cpp index 34515c73..5421fffe 100644 --- a/physx/source/lowleveldynamics/src/DyDynamics.cpp +++ b/physx/source/lowleveldynamics/src/DyDynamics.cpp @@ -1360,6 +1360,11 @@ public: if(numHeaders) { + PX_ASSERT(mContext.mSimulationController); + bool locked = mContext.mSimulationController->__shapeInterationLock.trylock(); + if(!locked) + PxDebugBreak(); + const PxU32 unrollSize = 8; for(PxU32 a = 0; a < numHeaders; a+= unrollSize) { @@ -1369,6 +1374,9 @@ public: postProcessTask->setContinuation(mCont); postProcessTask->removeReference(); } + if(locked) + mContext.mSimulationController->__shapeInterationLock.unlock(); + } } mThreadContext.contactDescArraySize = PxU32(contactDescPtr - mThreadContext.contactConstraintDescArray); diff --git a/physx/source/simulationcontroller/src/ScScene.cpp b/physx/source/simulationcontroller/src/ScScene.cpp index 6bf49fee..f7a6f5d5 100644 --- a/physx/source/simulationcontroller/src/ScScene.cpp +++ b/physx/source/simulationcontroller/src/ScScene.cpp @@ -949,6 +949,7 @@ Sc::Scene::Scene(const PxSceneDesc& desc, PxU64 contextID) : mSimulationControllerCallback = PX_NEW(ScSimulationControllerCallback)(this); mSimulationController = PX_NEW(SimulationController)(mSimulationControllerCallback); + mDynamicsContext->setSimulationController(mSimulationController); if (!useGpuBroadphase) mAABBManager = createAABBManagerCPU(desc, broadPhase, mBoundsArray, mContactDistance, allocator, contextID); @@ -3412,6 +3413,12 @@ public: virtual void runInternal() { + PX_PROFILE_ZONE("InteractionNewTouchTask", getContextId()); + PX_ASSERT(mNphaseCore->getScene().getSimulationController()); + bool locked = mNphaseCore->getScene().getSimulationController()->__shapeInterationLock.trylock(); + if(!locked) + PxDebugBreak(); + mNphaseCore->lockReports(); for (PxU32 i = 0; i < mNbEvents; ++i) { @@ -3421,6 +3428,8 @@ public: si->managerNewTouch(0, true, mOutputs); } mNphaseCore->unlockReports(); + if(!locked) + mNphaseCore->getScene().getSimulationController()->__shapeInterationLock.unlock(); } private: PX_NOCOPY(InteractionNewTouchTask) -- 2.33.0.windows.2