From 2ba24e17162587eeae9f9ca35e012ad0b466dc62 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 26 Apr 2013 00:46:29 -0700 Subject: [PATCH] fixed a couple bugs in VoxelNodeBag --- libraries/voxels/src/VoxelNodeBag.cpp | 11 ++++------- libraries/voxels/src/VoxelNodeBag.h | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/libraries/voxels/src/VoxelNodeBag.cpp b/libraries/voxels/src/VoxelNodeBag.cpp index d9e27d5500..3c001177d7 100644 --- a/libraries/voxels/src/VoxelNodeBag.cpp +++ b/libraries/voxels/src/VoxelNodeBag.cpp @@ -25,14 +25,11 @@ const int GROW_BAG_BY = 500; // put a node into the bag void VoxelNodeBag::insert(VoxelNode* node) { -printf("VoxelNodeBag::insert(node) node="); -node->printDebugDetails(""); - // Search for where we should live in the bag (sorted) // Note: change this to binary search... instead of linear! int insertAt = _elementsInUse; for (int i = 0; i < _elementsInUse; i++) { - + // compare the newNode to the elements already in the bag OctalTreeDepth comparison = compareOctalCodes(_bagElements[i]->octalCode,node->octalCode); @@ -60,13 +57,13 @@ node->printDebugDetails(""); if (oldBag) { // copy old elements into the new bag, but leave a space where we need to // insert the new node - memcpy(_bagElements, oldBag, insertAt); - memcpy(&_bagElements[insertAt+1], &oldBag[insertAt], (_elementsInUse-insertAt)); + memcpy(_bagElements, oldBag, insertAt*sizeof(VoxelNode*)); + memcpy(&_bagElements[insertAt+1], &oldBag[insertAt], (_elementsInUse-insertAt)*sizeof(VoxelNode*)); } } else { // move existing elements further back in the bag array, leave a space where we need to // insert the new node - memcpy(&_bagElements[insertAt+1], &_bagElements[insertAt], (_elementsInUse-insertAt)); + memmove(&_bagElements[insertAt+1], &_bagElements[insertAt], (_elementsInUse-insertAt)*sizeof(VoxelNode*)); } _bagElements[insertAt] = node; _elementsInUse++; diff --git a/libraries/voxels/src/VoxelNodeBag.h b/libraries/voxels/src/VoxelNodeBag.h index 4d1f3efb19..75943eb6b2 100644 --- a/libraries/voxels/src/VoxelNodeBag.h +++ b/libraries/voxels/src/VoxelNodeBag.h @@ -29,7 +29,7 @@ public: void insert(VoxelNode* node); // put a node into the bag VoxelNode* extract(); // pull a node out of the bag (could come in any order) - bool isEmpty() const { return (_elementsInUse > 0); } + bool isEmpty() const { return (_elementsInUse == 0); } int count() const { return _elementsInUse; } private: