diff --git a/assignment-client/src/octree/OctreeQueryNode.cpp b/assignment-client/src/octree/OctreeQueryNode.cpp index 5c882fd032..dfaf641753 100644 --- a/assignment-client/src/octree/OctreeQueryNode.cpp +++ b/assignment-client/src/octree/OctreeQueryNode.cpp @@ -62,6 +62,7 @@ void OctreeQueryNode::nodeKilled() { // while the thread actually shuts down _octreeSendThread->setIsShuttingDown(); } + nodeBag.unhookNotifications(); // if our node is shutting down, then we no longer need octree element notifications } void OctreeQueryNode::forceNodeShutdown() { diff --git a/libraries/octree/src/OctreeElementBag.cpp b/libraries/octree/src/OctreeElementBag.cpp index 9f63b5b071..d4084101cb 100644 --- a/libraries/octree/src/OctreeElementBag.cpp +++ b/libraries/octree/src/OctreeElementBag.cpp @@ -16,13 +16,20 @@ OctreeElementBag::OctreeElementBag() : _bagElements() { OctreeElement::addDeleteHook(this); + _hooked = true; }; OctreeElementBag::~OctreeElementBag() { - OctreeElement::removeDeleteHook(this); + unhookNotifications(); deleteAll(); } +void OctreeElementBag::unhookNotifications() { + if (_hooked) { + OctreeElement::removeDeleteHook(this); + } +} + void OctreeElementBag::elementDeleted(OctreeElement* element) { qDebug() << "OctreeElementBag::elementDeleted()..."; remove(element); // note: remove can safely handle nodes that aren't in it, so we don't need to check contains() diff --git a/libraries/octree/src/OctreeElementBag.h b/libraries/octree/src/OctreeElementBag.h index afc34bf1a6..8c18ece773 100644 --- a/libraries/octree/src/OctreeElementBag.h +++ b/libraries/octree/src/OctreeElementBag.h @@ -36,8 +36,11 @@ public: void deleteAll(); virtual void elementDeleted(OctreeElement* element); + void unhookNotifications(); + private: QSet _bagElements; + bool _hooked; }; #endif // hifi_OctreeElementBag_h