From 48e35ec6cb2010f388ed553125ec470b65cfbd1f Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 8 Aug 2013 14:29:58 -0700 Subject: [PATCH 1/2] fix delete local voxels in case of last voxel server going away --- interface/src/VoxelSystem.cpp | 22 +++++++++++++++++----- interface/src/VoxelSystem.h | 2 ++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index bc9502b0ee..1e3c47b8ba 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -63,6 +63,7 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) : _abandonedVBOSlots = 0; _falseColorizeBySource = false; _dataSourceID = UNKNOWN_NODE_ID; + _voxelServerCount = 0; } void VoxelSystem::nodeDeleted(VoxelNode* node) { @@ -1538,6 +1539,7 @@ void VoxelSystem::nodeAdded(Node* node) { if (node->getType() == NODE_TYPE_VOXEL_SERVER) { uint16_t nodeID = node->getNodeID(); printf("VoxelSystem... voxel server %u added...\n", nodeID); + _voxelServerCount++; } } @@ -1545,8 +1547,11 @@ bool VoxelSystem::killSourceVoxelsOperation(VoxelNode* node, void* extraData) { uint16_t killedNodeID = *(uint16_t*)extraData; for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { VoxelNode* childNode = node->getChildAtIndex(i); - if (childNode && childNode->getSourceID()== killedNodeID) { - node->safeDeepDeleteChildAtIndex(i); + if (childNode) { + uint16_t childNodeID = childNodeID = childNode->getSourceID(); + if (childNodeID == killedNodeID) { + node->safeDeepDeleteChildAtIndex(i); + } } } return true; @@ -1554,12 +1559,19 @@ bool VoxelSystem::killSourceVoxelsOperation(VoxelNode* node, void* extraData) { void VoxelSystem::nodeKilled(Node* node) { if (node->getType() == NODE_TYPE_VOXEL_SERVER) { + _voxelServerCount--; uint16_t nodeID = node->getNodeID(); printf("VoxelSystem... voxel server %u removed...\n", nodeID); - // Kill any voxels from the local tree - _tree->recurseTreeWithOperation(killSourceVoxelsOperation, &nodeID); - _tree->setDirtyBit(); + if (_voxelServerCount > 0) { + // Kill any voxels from the local tree that match this nodeID + _tree->recurseTreeWithOperation(killSourceVoxelsOperation, &nodeID); + _tree->setDirtyBit(); + } else { + // Last server, take the easy way and kill all the local voxels! + _tree->eraseAllVoxels(); + _voxelsInWriteArrays = _voxelsInReadArrays = 0; // better way to do this?? + } setupNewVoxelsForDrawing(); } } diff --git a/interface/src/VoxelSystem.h b/interface/src/VoxelSystem.h index 60396adcb0..94e2d42e5e 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -206,6 +206,8 @@ private: bool _falseColorizeBySource; int _dataSourceID; + + int _voxelServerCount; }; #endif From 6d4ebda1ffe43f3fa633c53dcbe0861ba697fdba Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 8 Aug 2013 14:30:46 -0700 Subject: [PATCH 2/2] fix delete local voxels in case of last voxel server going away --- interface/src/VoxelSystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index 1e3c47b8ba..2197b1b1bb 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -1548,7 +1548,7 @@ bool VoxelSystem::killSourceVoxelsOperation(VoxelNode* node, void* extraData) { for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { VoxelNode* childNode = node->getChildAtIndex(i); if (childNode) { - uint16_t childNodeID = childNodeID = childNode->getSourceID(); + uint16_t childNodeID = childNode->getSourceID(); if (childNodeID == killedNodeID) { node->safeDeepDeleteChildAtIndex(i); }