From ca7225e525a974585b34df5efaf1a8c0676ffc22 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 17 Oct 2013 18:45:52 -0700 Subject: [PATCH] fix reset of VoxelSystem on eraseAllVoxels() --- interface/src/VoxelSystem.cpp | 3 ++- libraries/voxels/src/VoxelNode.cpp | 5 ++++- libraries/voxels/src/VoxelTree.cpp | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index bc2d353bf9..4a5f616ee6 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -73,6 +73,7 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) _writeRenderFullVBO = true; _readRenderFullVBO = true; _tree = new VoxelTree(); + _tree->rootNode->setVoxelSystem(this); pthread_mutex_init(&_bufferWriteLock, NULL); pthread_mutex_init(&_treeLock, NULL); @@ -133,7 +134,7 @@ void VoxelSystem::voxelUpdated(VoxelNode* node) { } if (node->getVoxelSystem() == this) { - bool shouldRender = false; // assume we don't need to render it + bool shouldRender = false; // assume we don't need to render it // if it's colored, we might need to render it! shouldRender = node->calculateShouldRender(_viewFrustum); diff --git a/libraries/voxels/src/VoxelNode.cpp b/libraries/voxels/src/VoxelNode.cpp index e850be7ad8..6f274ba85f 100644 --- a/libraries/voxels/src/VoxelNode.cpp +++ b/libraries/voxels/src/VoxelNode.cpp @@ -79,6 +79,7 @@ void VoxelNode::init(unsigned char * octalCode) { _unknownBufferIndex = true; setBufferIndex(GLBUFFER_INDEX_UNKNOWN); + setVoxelSystem(NULL); _isDirty = true; _shouldRender = false; @@ -146,7 +147,9 @@ std::map VoxelNode::_mapIndexToVoxelSystemPointers; VoxelSystem* VoxelNode::getVoxelSystem() const { if (_voxelSystemIndex > INDEX_FOR_NULL) { if (_mapIndexToVoxelSystemPointers.end() != _mapIndexToVoxelSystemPointers.find(_voxelSystemIndex)) { - return _mapIndexToVoxelSystemPointers[_voxelSystemIndex]; + + VoxelSystem* voxelSystem = _mapIndexToVoxelSystemPointers[_voxelSystemIndex]; + return voxelSystem; } } return NULL; diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index eadba04e65..6c1fe42b76 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -476,7 +476,9 @@ void VoxelTree::deleteVoxelCodeFromTreeRecursion(VoxelNode* node, void* extraDat void VoxelTree::eraseAllVoxels() { // XXXBHG Hack attack - is there a better way to erase the voxel tree? delete rootNode; // this will recurse and delete all children + VoxelSystem* voxelSystem = rootNode->getVoxelSystem(); rootNode = new VoxelNode(); + rootNode->setVoxelSystem(voxelSystem); _isDirty = true; }