lock our node while using it to prevent crash on domain shutdown

This commit is contained in:
ZappoMan 2013-11-06 13:52:31 -08:00
parent 5cd0ecde18
commit c3914e648f

View file

@ -27,21 +27,25 @@ bool VoxelSendThread::process() {
uint64_t start = usecTimestampNow(); uint64_t start = usecTimestampNow();
Node* node = NodeList::getInstance()->nodeWithUUID(_nodeUUID); Node* node = NodeList::getInstance()->nodeWithUUID(_nodeUUID);
VoxelNodeData* nodeData = NULL;
if (node) { if (node) {
node->lock(); // make sure the node list doesn't kill our node while we're using it
VoxelNodeData* nodeData = NULL;
nodeData = (VoxelNodeData*) node->getLinkedData(); nodeData = (VoxelNodeData*) node->getLinkedData();
}
int packetsSent = 0; int packetsSent = 0;
// Sometimes the node data has not yet been linked, in which case we can't really do anything // Sometimes the node data has not yet been linked, in which case we can't really do anything
if (nodeData) { if (nodeData) {
bool viewFrustumChanged = nodeData->updateCurrentViewFrustum(); bool viewFrustumChanged = nodeData->updateCurrentViewFrustum();
if (_myServer->wantsDebugVoxelSending()) { if (_myServer->wantsDebugVoxelSending()) {
printf("nodeData->updateCurrentViewFrustum() changed=%s\n", debug::valueOf(viewFrustumChanged)); printf("nodeData->updateCurrentViewFrustum() changed=%s\n", debug::valueOf(viewFrustumChanged));
}
packetsSent = deepestLevelVoxelDistributor(node, nodeData, viewFrustumChanged);
} }
packetsSent = deepestLevelVoxelDistributor(node, nodeData, viewFrustumChanged);
node->unlock(); // we're done with this node for now.
} }
// dynamically sleep until we need to fire off the next set of voxels // dynamically sleep until we need to fire off the next set of voxels
@ -55,6 +59,7 @@ bool VoxelSendThread::process() {
std::cout << "Last send took too much time, not sleeping!\n"; std::cout << "Last send took too much time, not sleeping!\n";
} }
} }
return isStillRunning(); // keep running till they terminate us return isStillRunning(); // keep running till they terminate us
} }