diff --git a/newton-4.00/applications/ndSandbox/demos/ndAdvancedIndustrialRobot.cpp b/newton-4.00/applications/ndSandbox/demos/ndAdvancedIndustrialRobot.cpp index 3477b281e..5e11fd72e 100644 --- a/newton-4.00/applications/ndSandbox/demos/ndAdvancedIndustrialRobot.cpp +++ b/newton-4.00/applications/ndSandbox/demos/ndAdvancedIndustrialRobot.cpp @@ -912,7 +912,7 @@ namespace ndAdvancedRobot ,m_discountFactor(0.99f) ,m_horizon(ndFloat32(1.0f) / (ndFloat32(1.0f) - m_discountFactor)) ,m_lastEpisode(-1) - ,m_stopTraining(300 * 1000000) + ,m_stopTraining(500 * 1000000) ,m_modelIsTrained(false) { //ndWorld* const world = scene->GetWorld(); diff --git a/newton-4.00/applications/ndSandbox/toolbox/ndDebugDisplay.cpp b/newton-4.00/applications/ndSandbox/toolbox/ndDebugDisplay.cpp index d13d8b566..cc322d362 100644 --- a/newton-4.00/applications/ndSandbox/toolbox/ndDebugDisplay.cpp +++ b/newton-4.00/applications/ndSandbox/toolbox/ndDebugDisplay.cpp @@ -677,6 +677,7 @@ void ndDebugDisplay::ndContactPoints::UpdateBuffers(ndDemoEntityManager* const s m_points.SetCount(0); ndWorld* const world = scene->GetWorld(); const ndContactArray& contactList = world->GetContactList(); + ndScopeSpinLock contactLock(contactList.GetLock()); glVector3 color(GLfloat(1.0f), GLfloat(0.0f), GLfloat(0.0f)); for (ndInt32 i = 0; i < contactList.GetCount(); ++i) @@ -722,6 +723,8 @@ void ndDebugDisplay::ndNormalForces::UpdateBuffers(ndDemoEntityManager* const sc ndWorld* const world = scene->GetWorld(); const ndContactArray& contactList = world->GetContactList(); + ndScopeSpinLock contactLock(contactList.GetLock()); + for (ndInt32 i = 0; i < contactList.GetCount(); ++i) { const ndContact* const contact = contactList[i]; diff --git a/newton-4.00/sdk/dCollision/ndContactArray.cpp b/newton-4.00/sdk/dCollision/ndContactArray.cpp index 8971b5d1a..449f1fd86 100644 --- a/newton-4.00/sdk/dCollision/ndContactArray.cpp +++ b/newton-4.00/sdk/dCollision/ndContactArray.cpp @@ -60,6 +60,7 @@ ndContact* ndContactArray::CreateContact(ndBodyKinematic* const body0, ndBodyKin ndContact* const contact = new ndContact; contact->SetBodies(body0, body1); contact->AttachToBodies(); + ndScopeSpinLock lock(m_lock); PushBack(contact); return contact; @@ -76,6 +77,7 @@ void ndContactArray::DetachContact(ndContact* const contact) void ndContactArray::DeleteAllContacts() { + ndScopeSpinLock lock(m_lock); for (ndInt32 i = ndInt32(GetCount()) - 1; i >= 0; --i) { ndContact* const contact = m_array[i]; diff --git a/newton-4.00/sdk/dCollision/ndContactArray.h b/newton-4.00/sdk/dCollision/ndContactArray.h index 7a13e6f27..9e8e7f4e4 100644 --- a/newton-4.00/sdk/dCollision/ndContactArray.h +++ b/newton-4.00/sdk/dCollision/ndContactArray.h @@ -36,10 +36,16 @@ class ndContactArray : public ndArray void DetachContact(ndContact* const contact); ndContact* CreateContact(ndBodyKinematic* const body0, ndBodyKinematic* const body1); + ndSpinLock& GetLock() const; D_COLLISION_API ndInt32 GetActiveContacts() const; private: mutable ndSpinLock m_lock; }; +inline ndSpinLock& ndContactArray::GetLock() const +{ + return m_lock; +} + #endif \ No newline at end of file diff --git a/newton-4.00/sdk/dCollision/ndScene.cpp b/newton-4.00/sdk/dCollision/ndScene.cpp index b971a69f2..3ed4450bb 100644 --- a/newton-4.00/sdk/dCollision/ndScene.cpp +++ b/newton-4.00/sdk/dCollision/ndScene.cpp @@ -277,6 +277,7 @@ bool ndScene::RemoveBody(const ndSharedPtr& body) m_forceBalanceSceneCounter = 0; m_bvhSceneManager.RemoveBody(kinematicBody); + //ndAssert(0); ndBodyKinematic::ndContactMap& contactMap = kinematicBody->GetContactMap(); while (contactMap.GetRoot()) { @@ -1201,12 +1202,10 @@ void ndScene::Cleanup() m_contactArray.DeleteAllContacts(); ndFreeListAlloc::Flush(); - m_contactArray.Resize(1024); m_sceneBodyArray.Resize(1024); m_activeConstraintArray.Resize(1024); m_scratchBuffer.Resize(1024 * sizeof(void*)); - m_contactArray.SetCount(0); m_scratchBuffer.SetCount(0); m_sceneBodyArray.SetCount(0); m_activeConstraintArray.SetCount(0); @@ -1592,6 +1591,7 @@ void ndScene::CalculateContacts() { D_TRACKTIME(); m_activeConstraintArray.SetCount(0); + ndScopeSpinLock lock(m_contactArray.GetLock()); const ndInt32 contactCount = ndInt32(m_contactArray.GetCount() + m_newPairs.GetCount()); m_contactArray.SetCount(contactCount); if (contactCount) @@ -1653,6 +1653,7 @@ void ndScene::DeleteDeadContacts() }; ndUnsigned32 prefixScan[5]; + ndScopeSpinLock lock(m_contactArray.GetLock()); if (m_contactArray.GetCount()) { D_TRACKTIME();