Merge pull request #724 from ZappoMan/bug_fixes

fix voxel-server crash
This commit is contained in:
Stephen Birarda 2013-07-25 13:15:47 -07:00
commit 718fa291cf

View file

@ -1071,6 +1071,9 @@ int VoxelTree::encodeTreeBitstream(VoxelNode* node, unsigned char* outputBuffer,
int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outputBuffer, int availableBytes, VoxelNodeBag& bag, int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outputBuffer, int availableBytes, VoxelNodeBag& bag,
EncodeBitstreamParams& params, int& currentEncodeLevel) const { EncodeBitstreamParams& params, int& currentEncodeLevel) const {
// you can't call this without a valid node
assert(node);
// How many bytes have we written so far at this level; // How many bytes have we written so far at this level;
int bytesAtThisLevel = 0; int bytesAtThisLevel = 0;
@ -1228,6 +1231,7 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outp
} }
// track stats // track stats
// must check childNode here, because it could be we got here with no childNode
if (params.stats && childNode) { if (params.stats && childNode) {
params.stats->traversed(childNode); params.stats->traversed(childNode);
} }
@ -1243,7 +1247,8 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outp
bool childIsInView = (childNode && (!params.viewFrustum || childNode->isInView(*params.viewFrustum))); bool childIsInView = (childNode && (!params.viewFrustum || childNode->isInView(*params.viewFrustum)));
if (!childIsInView) { if (!childIsInView) {
if (params.stats) { // must check childNode here, because it could be we got here because there was no childNode
if (params.stats && childNode) {
params.stats->skippedOutOfView(childNode); params.stats->skippedOutOfView(childNode);
} }
} else { } else {
@ -1253,6 +1258,7 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outp
boundaryDistanceForRenderLevel(childNode->getLevel() + params.boundaryLevelAdjust); boundaryDistanceForRenderLevel(childNode->getLevel() + params.boundaryLevelAdjust);
if (!(distance < boundaryDistance)) { if (!(distance < boundaryDistance)) {
// don't need to check childNode here, because we can't get here with no childNode
if (params.stats) { if (params.stats) {
params.stats->skippedDistance(childNode); params.stats->skippedDistance(childNode);
} }
@ -1306,9 +1312,11 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outp
// track some stats // track some stats
if (params.stats) { if (params.stats) {
// don't need to check childNode here, because we can't get here with no childNode
if (!shouldRender && childNode->isLeaf()) { if (!shouldRender && childNode->isLeaf()) {
params.stats->skippedDistance(childNode); params.stats->skippedDistance(childNode);
} }
// don't need to check childNode here, because we can't get here with no childNode
if (childIsOccluded) { if (childIsOccluded) {
params.stats->skippedOccluded(childNode); params.stats->skippedOccluded(childNode);
} }
@ -1339,6 +1347,7 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outp
inViewWithColorCount++; inViewWithColorCount++;
} else { } else {
// otherwise just track stats of the items we discarded // otherwise just track stats of the items we discarded
// don't need to check childNode here, because we can't get here with no childNode
if (params.stats) { if (params.stats) {
if (childWasInView) { if (childWasInView) {
params.stats->skippedWasInView(childNode); params.stats->skippedWasInView(childNode);
@ -1368,6 +1377,7 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outp
writeToThisLevelBuffer += BYTES_PER_COLOR; // move the pointer for color writeToThisLevelBuffer += BYTES_PER_COLOR; // move the pointer for color
bytesAtThisLevel += BYTES_PER_COLOR; // keep track of byte count for color bytesAtThisLevel += BYTES_PER_COLOR; // keep track of byte count for color
// don't need to check childNode here, because we can't get here with no childNode
if (params.stats) { if (params.stats) {
params.stats->colorSent(childNode); params.stats->colorSent(childNode);
} }
@ -1407,6 +1417,7 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outp
} else { } else {
bag.insert(node); bag.insert(node);
// don't need to check node here, because we can't get here with no node
if (params.stats) { if (params.stats) {
params.stats->didntFit(node); params.stats->didntFit(node);
} }