History

fixed a couple crashes and cleaned up some code

ZappoMan committed 13 years ago

Commit 4be07ec1 parent 53e24863 files · +54 −32Browse files

Showing the changes to interface/src/VoxelSystem.cpp (1 of 3 files). Show all

Unified · Split

interface/src/VoxelSystem.cpp+50−31
@@ -109,8 +109,14 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) · 108 unmodified lines
109109 }
110110
111111 void VoxelSystem::voxelDeleted(VoxelNode* node) {
112− if (node->isKnownBufferIndex() && (node->getVoxelSystem() == this)) {
113− forceRemoveNodeFromArrays(node);
112+ if (node->getVoxelSystem() == this) {
113+ if (_voxelsInWriteArrays != 0) {
114+ forceRemoveNodeFromArrays(node);
115+ } else {
116+ if (Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings)) {
117+ printf("VoxelSystem::voxelDeleted() while _voxelsInWriteArrays==0, is that expected? \n");
118+ }
119+ }
114120 }
115121 }
116122
@@ -223,10 +229,15 @@ void VoxelSystem::freeBufferIndex(glBufferIndex index) { · 106 unmodified lines
223229 // This will run through the list of _freeIndexes and reset their VBO array values to be "invisible".
224230 void VoxelSystem::clearFreeBufferIndexes() {
225231 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "###### clearFreeBufferIndexes()");
232+ _voxelsInWriteArrays = 0; // reset our VBO
233+ _abandonedVBOSlots = 0;
234+
235+ // clear out freeIndexes
226236 pthread_mutex_lock(&_freeIndexLock);
227237 _freeIndexes.clear();
228− _abandonedVBOSlots = 0;
229238 pthread_mutex_unlock(&_freeIndexLock);
239+
240+ clearAllNodesBufferIndex();
230241 }
231242
232243 VoxelSystem::~VoxelSystem() {
@@ -438,7 +449,6 @@ void VoxelSystem::initVoxelMemory() { · 205 unmodified lines
438449
439450 // Global Normals mode uses a technique of not including normals on any voxel vertices, and instead
440451 // rendering the voxel faces in 6 passes that use a global call to glNormal3f()
441− qDebug("Using Global Normals...\n");
442452 setupFaceIndices(_vboIndicesTop, identityIndicesTop);
443453 setupFaceIndices(_vboIndicesBottom, identityIndicesBottom);
444454 setupFaceIndices(_vboIndicesLeft, identityIndicesLeft);
@@ -596,11 +606,7 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 151 unmodified lines
596606
597607 while (totalLength <= numBytes) {
598608 if (0==strcmp(command,(char*)"erase all")) {
599− qDebug("got Z message == erase all\n");
600− pthread_mutex_lock(&_treeLock);
601− _tree->eraseAllVoxels();
602− pthread_mutex_unlock(&_treeLock);
603− _voxelsInReadArrays = _voxelsInWriteArrays = 0; // better way to do this??
609+ qDebug("got Z message == erase all - NOT SUPPORTED ON INTERFACE\n");
604610 }
605611 if (0==strcmp(command,(char*)"add scene")) {
606612 qDebug("got Z message == add scene - NOT SUPPORTED ON INTERFACE\n");
@@ -652,8 +658,6 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 45 unmodified lines
652658 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), buffer);
653659 _callsToTreesToArrays++;
654660 if (_writeRenderFullVBO) {
655− printf("resetting _freeIndexes and _voxelsInWriteArrays\n");
656− _voxelsInWriteArrays = 0; // reset our VBO
657661 clearFreeBufferIndexes();
658662 }
659663 _voxelsUpdated = newTreeToArrays(_tree->rootNode);
@@ -972,10 +976,10 @@ int VoxelSystem::updateNodeInArrays(VoxelNode* node, bool reuseIndex, bool force · 312 unmodified lines
972976 updateArraysDetails(nodeIndex, startVertex, voxelScale, node->getColor());
973977 return 1; // updated!
974978 } else {
975− // If we shouldn't render, but we did have a known index, then we will need to release our index
976− if (reuseIndex && node->isKnownBufferIndex()) {
977− forceRemoveNodeFromArrays(node);
978− return 1; // updated!
979+ // If we shouldn't render, and we're in reuseIndex mode, then free our index, this only operates
980+ // on nodes with known index values, so it's safe to call for any node.
981+ if (reuseIndex) {
982+ return forceRemoveNodeFromArrays(node);
979983 }
980984 }
981985 }
@@ -1284,8 +1288,11 @@ void VoxelSystem::removeScaleAndReleaseProgram(bool texture) { · 302 unmodified lines
12841288 int VoxelSystem::_nodeCount = 0;
12851289
12861290 void VoxelSystem::killLocalVoxels() {
1291+ pthread_mutex_lock(&_treeLock);
12871292 _tree->eraseAllVoxels();
1288− _voxelsInWriteArrays = _voxelsInReadArrays = 0; // better way to do this??
1293+ pthread_mutex_unlock(&_treeLock);
1294+ clearFreeBufferIndexes();
1295+ _voxelsInReadArrays = 0; // do we need to do this?
12891296 setupNewVoxelsForDrawing();
12901297 }
12911298
@@ -1298,8 +1305,12 @@ bool VoxelSystem::clearAllNodesBufferIndexOperation(VoxelNode* node, void* extra · 6 unmodified lines
12981305
12991306 void VoxelSystem::clearAllNodesBufferIndex() {
13001307 _nodeCount = 0;
1308+ pthread_mutex_lock(&_treeLock);
13011309 _tree->recurseTreeWithOperation(clearAllNodesBufferIndexOperation);
1302− qDebug("clearing buffer index of %d nodes\n", _nodeCount);
1310+ pthread_mutex_unlock(&_treeLock);
1311+ if (Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings)) {
1312+ qDebug("clearing buffer index of %d nodes\n", _nodeCount);
1313+ }
13031314 }
13041315
13051316 bool VoxelSystem::forceRedrawEntireTreeOperation(VoxelNode* node, void* extraData) {
@@ -1700,8 +1711,7 @@ bool VoxelSystem::hideAllSubTreeOperation(VoxelNode* node, void* extraData) { · 394 unmodified lines
17001711 if (node->isKnownBufferIndex()) {
17011712 args->nodesRemoved++;
17021713 VoxelSystem* thisVoxelSystem = args->thisVoxelSystem;
1703− thisVoxelSystem->forceRemoveNodeFromArrays(node);
1704− thisVoxelSystem->_voxelsUpdated++;
1714+ thisVoxelSystem->_voxelsUpdated += thisVoxelSystem->forceRemoveNodeFromArrays(node);
17051715 thisVoxelSystem->setupNewVoxelsForDrawingSingleNode();
17061716 }
17071717
@@ -1714,10 +1724,10 @@ bool VoxelSystem::showAllSubTreeOperation(VoxelNode* node, void* extraData) { · 6 unmodified lines
17141724 args->nodesInside++;
17151725
17161726 if (node->getShouldRender() && !node->isKnownBufferIndex()) {
1717− node->setDirtyBit(); // will this make it draw?
1727+ node->setDirtyBit(); // will this make it draw!
17181728 }
17191729
1720− return true;
1730+ return true; // keep recursing!
17211731 }
17221732
17231733
@@ -1841,7 +1851,7 @@ void VoxelSystem::falseColorizeRandomEveryOther() { · 117 unmodified lines
18411851
18421852 class collectStatsForTreesAndVBOsArgs {
18431853 public:
1844− collectStatsForTreesAndVBOsArgs() :
1854+ collectStatsForTreesAndVBOsArgs(int maxVoxels) :
18451855 totalNodes(0),
18461856 dirtyNodes(0),
18471857 shouldRenderNodes(0),
@@ -1852,8 +1862,13 @@ public: · 4 unmodified lines
18521862 duplicateVBOIndex(0),
18531863 leafNodes(0)
18541864 {
1855− memset(hasIndexFound, false, DEFAULT_MAX_VOXELS_PER_SYSTEM * sizeof(bool));
1865+ hasIndexFound = new bool[maxVoxels];
1866+ memset(hasIndexFound, false, maxVoxels * sizeof(bool));
18561867 };
1868+
1869+ ~collectStatsForTreesAndVBOsArgs() {
1870+ delete[] hasIndexFound;
1871+ }
18571872
18581873 unsigned long totalNodes;
18591874 unsigned long dirtyNodes;
@@ -1867,7 +1882,7 @@ public: · 7 unmodified lines
18671882
18681883 unsigned long expectedMax;
18691884
1870− bool hasIndexFound[DEFAULT_MAX_VOXELS_PER_SYSTEM];
1885+ bool* hasIndexFound;
18711886 };
18721887
18731888 bool VoxelSystem::collectStatsForTreesAndVBOsOperation(VoxelNode* node, void* extraData) {
@@ -1934,7 +1949,7 @@ void VoxelSystem::collectStatsForTreesAndVBOs() { · 60 unmodified lines
19341949 }
19351950 }
19361951
1937− collectStatsForTreesAndVBOsArgs args;
1952+ collectStatsForTreesAndVBOsArgs args(_maxVoxels);
19381953 args.expectedMax = _voxelsInWriteArrays;
19391954
19401955 qDebug("CALCULATING Local Voxel Tree Statistics >>>>>>>>>>>>\n");
@@ -1953,7 +1968,7 @@ void VoxelSystem::collectStatsForTreesAndVBOs() { · 12 unmodified lines
19531968 glBufferIndex minInVBO = GLBUFFER_INDEX_UNKNOWN;
19541969 glBufferIndex maxInVBO = 0;
19551970
1956− for (glBufferIndex i = 0; i < DEFAULT_MAX_VOXELS_PER_SYSTEM; i++) {
1971+ for (glBufferIndex i = 0; i < _maxVoxels; i++) {
19571972 if (args.hasIndexFound[i]) {
19581973 minInVBO = std::min(minInVBO,i);
19591974 maxInVBO = std::max(maxInVBO,i);
@@ -1972,13 +1987,12 @@ void VoxelSystem::collectStatsForTreesAndVBOs() { · 12 unmodified lines
19721987
19731988 void VoxelSystem::deleteVoxelAt(float x, float y, float z, float s) {
19741989 pthread_mutex_lock(&_treeLock);
1975−
19761990 _tree->deleteVoxelAt(x, y, z, s);
1991+ pthread_mutex_unlock(&_treeLock);
19771992
19781993 // redraw!
19791994 setupNewVoxelsForDrawing(); // do we even need to do this? Or will the next network receive kick in?
19801995
1981− pthread_mutex_unlock(&_treeLock);
19821996 };
19831997
19841998 VoxelNode* VoxelSystem::getVoxelAt(float x, float y, float z, float s) const {
@@ -2313,17 +2327,22 @@ void VoxelSystem::nodeKilled(Node* node) { · 328 unmodified lines
23132327
23142328 if (_voxelServerCount > 0) {
23152329 // Kill any voxels from the local tree that match this nodeID
2330+ pthread_mutex_lock(&_treeLock);
23162331 _tree->recurseTreeWithOperation(killSourceVoxelsOperation, &nodeID);
2332+ pthread_mutex_unlock(&_treeLock);
23172333 _tree->setDirtyBit();
2334+ setupNewVoxelsForDrawing();
23182335 } else {
23192336 // Last server, take the easy way and kill all the local voxels!
2320− _tree->eraseAllVoxels();
2321− _voxelsInWriteArrays = _voxelsInReadArrays = 0; // better way to do this??
2337+ killLocalVoxels();
23222338 }
2323− setupNewVoxelsForDrawing();
23242339 }
23252340 }
23262341
2342+void VoxelSystem::domainChanged(QString domain) {
2343+ killLocalVoxels();
2344+}
2345+
23272346
23282347 unsigned long VoxelSystem::getFreeMemoryGPU() {
23292348 // We can't ask all GPUs how much memory they have in use, but we can ask them about how much is free.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t