From ba4c356d7f0bdcd4d318d6283c50bdb1f8359c02 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Wed, 12 Oct 2016 11:05:19 -0700 Subject: [PATCH] Deadlock fix in avatar grab action. Reverse the order we acquire the entityTree & holdActions locks, to avoid deadlocks when the network thread also acquires them. The network thread does this when hold actions from other avatars are received. --- interface/src/avatar/MyAvatar.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 19346e51db..27e827cb68 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -2283,12 +2283,13 @@ void MyAvatar::updateHoldActions(const AnimPose& prePhysicsPose, const AnimPose& EntityTreeRenderer* entityTreeRenderer = qApp->getEntities(); EntityTreePointer entityTree = entityTreeRenderer ? entityTreeRenderer->getTree() : nullptr; if (entityTree) { - // to prevent actions from adding or removing themselves from the _holdActions vector - // while we are iterating, we need to enter a critical section. - std::lock_guard guard(_holdActionsMutex); - // lateAvatarUpdate will modify entity position & orientation, so we need an entity write lock entityTree->withWriteLock([&] { + + // to prevent actions from adding or removing themselves from the _holdActions vector + // while we are iterating, we need to enter a critical section. + std::lock_guard guard(_holdActionsMutex); + for (auto& holdAction : _holdActions) { holdAction->lateAvatarUpdate(prePhysicsPose, postUpdatePose); }