From 07a4beac73ed8c789148816a52ed7d5ee00a5d02 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Mon, 7 Aug 2017 10:28:36 -0700 Subject: [PATCH] Fix the crash --- .../ui/overlays/ContextOverlayInterface.cpp | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/interface/src/ui/overlays/ContextOverlayInterface.cpp b/interface/src/ui/overlays/ContextOverlayInterface.cpp index e406d139d0..77b9424d2f 100644 --- a/interface/src/ui/overlays/ContextOverlayInterface.cpp +++ b/interface/src/ui/overlays/ContextOverlayInterface.cpp @@ -257,15 +257,23 @@ void ContextOverlayInterface::openMarketplace() { } void ContextOverlayInterface::enableEntityHighlight(const EntityItemID& entityItemID) { - if (!qApp->getEntities()->getTree()->findEntityByEntityItemID(entityItemID)->getShouldHighlight()) { - qCDebug(context_overlay) << "Setting 'shouldHighlight' to 'true' for Entity ID:" << entityItemID; - qApp->getEntities()->getTree()->findEntityByEntityItemID(entityItemID)->setShouldHighlight(true); - } + auto entityTree = qApp->getEntities()->getTree(); + entityTree->withReadLock([&] { + auto entityItem = entityTree->findEntityByEntityItemID(entityItemID); + if ((entityItem != NULL) && !entityItem->getShouldHighlight()) { + qCDebug(context_overlay) << "Setting 'shouldHighlight' to 'true' for Entity ID:" << entityItemID; + entityItem->setShouldHighlight(true); + } + }); } void ContextOverlayInterface::disableEntityHighlight(const EntityItemID& entityItemID) { - if (qApp->getEntities()->getTree()->findEntityByEntityItemID(entityItemID)->getShouldHighlight()) { - qCDebug(context_overlay) << "Setting 'shouldHighlight' to 'false' for Entity ID:" << entityItemID; - qApp->getEntities()->getTree()->findEntityByEntityItemID(entityItemID)->setShouldHighlight(false); - } + auto entityTree = qApp->getEntities()->getTree(); + entityTree->withReadLock([&] { + auto entityItem = entityTree->findEntityByEntityItemID(entityItemID); + if ((entityItem != NULL) && entityItem->getShouldHighlight()) { + qCDebug(context_overlay) << "Setting 'shouldHighlight' to 'false' for Entity ID:" << entityItemID; + entityItem->setShouldHighlight(false); + } + }); }