From 688bc179546ebab1fa431da1329b2cb947027ad1 Mon Sep 17 00:00:00 2001 From: atlante45 Date: Tue, 3 Sep 2013 13:37:25 -0700 Subject: [PATCH 1/7] Fixed avatar related files memory wastes --- interface/src/Balls.cpp | 4 ++ interface/src/Balls.h | 1 + interface/src/Menu.h | 3 + interface/src/VoxelSystem.cpp | 70 +++++++++++++--------- interface/src/VoxelSystem.h | 4 +- interface/src/avatar/AvatarVoxelSystem.cpp | 61 ++++++++++++------- interface/src/avatar/AvatarVoxelSystem.h | 4 +- interface/src/avatar/Face.cpp | 46 +++++++------- interface/src/avatar/Face.h | 8 ++- interface/src/avatar/Head.cpp | 49 +++++++-------- interface/src/avatar/Head.h | 13 ++-- libraries/shared/src/NodeList.h | 4 +- 12 files changed, 153 insertions(+), 114 deletions(-) diff --git a/interface/src/Balls.cpp b/interface/src/Balls.cpp index 20613b3448..693b38462b 100644 --- a/interface/src/Balls.cpp +++ b/interface/src/Balls.cpp @@ -38,6 +38,10 @@ Balls::Balls(int numberOfBalls) { _origin = glm::vec3(0, 0, 0); } +Balls::~Balls() { + delete[] _balls; +} + void Balls::moveOrigin(const glm::vec3& newOrigin) { glm::vec3 delta = newOrigin - _origin; if (glm::length(delta) > EPSILON) { diff --git a/interface/src/Balls.h b/interface/src/Balls.h index 440f340307..eefa71828a 100644 --- a/interface/src/Balls.h +++ b/interface/src/Balls.h @@ -14,6 +14,7 @@ const int NUMBER_SPRINGS = 4; class Balls { public: Balls(int numberOfBalls); + ~Balls(); void simulate(float deltaTime); void render(); diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 37d1644e5c..7a796e1aa9 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -31,6 +31,9 @@ struct ViewFrustumOffset { float up; }; +class BandwidthDialog; +class VoxelStatsDialog; + class Menu : public QMenuBar { Q_OBJECT public: diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index b0cbcf02c3..c8df22b270 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -125,6 +125,12 @@ VoxelSystem::~VoxelSystem() { pthread_mutex_destroy(&_bufferWriteLock); pthread_mutex_destroy(&_treeLock); + // Destroy glBuffers + glDeleteBuffers(1, &_vboVerticesID); + glDeleteBuffers(1, &_vboNormalsID); + glDeleteBuffers(1, &_vboColorsID); + glDeleteBuffers(1, &_vboIndicesID); + VoxelNode::removeDeleteHook(this); } @@ -532,9 +538,15 @@ glm::vec3 VoxelSystem::computeVoxelVertex(const glm::vec3& startVertex, float vo return startVertex + glm::vec3(identityVertex[0], identityVertex[1], identityVertex[2]) * voxelScale; } -ProgramObject* VoxelSystem::_perlinModulateProgram = 0; +bool VoxelSystem::_perlinModulateProgramInitialized = false; +ProgramObject VoxelSystem::_perlinModulateProgram; void VoxelSystem::init() { + if (_initialized) { + qDebug("[ERROR] VoxelSystem is already initialized.\n"); + return; + } + _callsToTreesToArrays = 0; _setupNewVoxelsForDrawingLastFinished = 0; _setupNewVoxelsForDrawingLastElapsed = 0; @@ -545,19 +557,6 @@ void VoxelSystem::init() { _voxelsInWriteArrays = 0; _voxelsInReadArrays = 0; - // we will track individual dirty sections with these arrays of bools - _writeVoxelDirtyArray = new bool[_maxVoxels]; - memset(_writeVoxelDirtyArray, false, _maxVoxels * sizeof(bool)); - _readVoxelDirtyArray = new bool[_maxVoxels]; - memset(_readVoxelDirtyArray, false, _maxVoxels * sizeof(bool)); - - // prep the data structures for incoming voxel data - _writeVerticesArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * _maxVoxels]; - _readVerticesArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * _maxVoxels]; - - _writeColorsArray = new GLubyte[VERTEX_POINTS_PER_VOXEL * _maxVoxels]; - _readColorsArray = new GLubyte[VERTEX_POINTS_PER_VOXEL * _maxVoxels]; - GLuint* indicesArray = new GLuint[INDICES_PER_VOXEL * _maxVoxels]; // populate the indicesArray @@ -611,20 +610,35 @@ void VoxelSystem::init() { // delete the indices and normals arrays that are no longer needed delete[] indicesArray; delete[] normalsArray; - + + + // we will track individual dirty sections with these arrays of bools + _writeVoxelDirtyArray = new bool[_maxVoxels]; + memset(_writeVoxelDirtyArray, false, _maxVoxels * sizeof(bool)); + _readVoxelDirtyArray = new bool[_maxVoxels]; + memset(_readVoxelDirtyArray, false, _maxVoxels * sizeof(bool)); + + // prep the data structures for incoming voxel data + _writeVerticesArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * _maxVoxels]; + _readVerticesArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * _maxVoxels]; + + _writeColorsArray = new GLubyte[VERTEX_POINTS_PER_VOXEL * _maxVoxels]; + _readColorsArray = new GLubyte[VERTEX_POINTS_PER_VOXEL * _maxVoxels]; + + // create our simple fragment shader if we're the first system to init - if (_perlinModulateProgram != 0) { - return; + if (!_perlinModulateProgramInitialized) { + switchToResourcesParentIfRequired(); + _perlinModulateProgram.addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/perlin_modulate.vert"); + _perlinModulateProgram.addShaderFromSourceFile(QGLShader::Fragment, "resources/shaders/perlin_modulate.frag"); + _perlinModulateProgram.link(); + + _perlinModulateProgram.bind(); + _perlinModulateProgram.setUniformValue("permutationNormalTexture", 0); + _perlinModulateProgram.release(); + + _perlinModulateProgramInitialized = true; } - switchToResourcesParentIfRequired(); - _perlinModulateProgram = new ProgramObject(); - _perlinModulateProgram->addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/perlin_modulate.vert"); - _perlinModulateProgram->addShaderFromSourceFile(QGLShader::Fragment, "resources/shaders/perlin_modulate.frag"); - _perlinModulateProgram->link(); - - _perlinModulateProgram->bind(); - _perlinModulateProgram->setUniformValue("permutationNormalTexture", 0); - _perlinModulateProgram->release(); } void VoxelSystem::updateFullVBOs() { @@ -749,7 +763,7 @@ void VoxelSystem::applyScaleAndBindProgram(bool texture) { glScalef(_treeScale, _treeScale, _treeScale); if (texture) { - _perlinModulateProgram->bind(); + _perlinModulateProgram.bind(); glBindTexture(GL_TEXTURE_2D, Application::getInstance()->getTextureCache()->getPermutationNormalTextureID()); } } @@ -759,7 +773,7 @@ void VoxelSystem::removeScaleAndReleaseProgram(bool texture) { glPopMatrix(); if (texture) { - _perlinModulateProgram->release(); + _perlinModulateProgram.release(); glBindTexture(GL_TEXTURE_2D, 0); } } diff --git a/interface/src/VoxelSystem.h b/interface/src/VoxelSystem.h index 7b6c001e8a..35931d3191 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -135,6 +135,7 @@ private: VoxelSystem(const VoxelSystem&); VoxelSystem& operator= (const VoxelSystem&); + bool _initialized; int _callsToTreesToArrays; VoxelNodeBag _removedVoxels; @@ -207,7 +208,8 @@ private: bool _voxelsDirty; - static ProgramObject* _perlinModulateProgram; + static bool _perlinModulateProgramInitialized; + static ProgramObject _perlinModulateProgram; int _hookID; std::vector _freeIndexes; diff --git a/interface/src/avatar/AvatarVoxelSystem.cpp b/interface/src/avatar/AvatarVoxelSystem.cpp index b6665fee31..2b33c05807 100644 --- a/interface/src/avatar/AvatarVoxelSystem.cpp +++ b/interface/src/avatar/AvatarVoxelSystem.cpp @@ -22,25 +22,39 @@ const int BONE_ELEMENTS_PER_VOXEL = BONE_ELEMENTS_PER_VERTEX * VERTICES_PER_VOXE AvatarVoxelSystem::AvatarVoxelSystem(Avatar* avatar) : VoxelSystem(AVATAR_TREE_SCALE, MAX_VOXELS_PER_AVATAR), - _mode(0), _avatar(avatar), _voxelReply(0) { + _initialized(false), + _mode(0), + _avatar(avatar), + _voxelReply(0) { // we may have been created in the network thread, but we live in the main thread moveToThread(Application::getInstance()->thread()); } -AvatarVoxelSystem::~AvatarVoxelSystem() { - delete[] _readBoneIndicesArray; - delete[] _readBoneWeightsArray; - delete[] _writeBoneIndicesArray; - delete[] _writeBoneWeightsArray; +AvatarVoxelSystem::~AvatarVoxelSystem() { + if (_initialized) { + delete[] _readBoneIndicesArray; + delete[] _readBoneWeightsArray; + delete[] _writeBoneIndicesArray; + delete[] _writeBoneWeightsArray; + + glDeleteBuffers(1, &_vboBoneIndicesID); + glDeleteBuffers(1, &_vboBoneWeightsID); + } } -ProgramObject* AvatarVoxelSystem::_skinProgram = 0; +bool AvatarVoxelSystem::_skinProgramInitialized = false; +ProgramObject AvatarVoxelSystem::_skinProgram; int AvatarVoxelSystem::_boneMatricesLocation; int AvatarVoxelSystem::_boneIndicesLocation; int AvatarVoxelSystem::_boneWeightsLocation; void AvatarVoxelSystem::init() { + if (_initialized) { + qDebug("[ERROR] AvatarVoxelSystem is already initialized.\n"); + return; + } + VoxelSystem::init(); // prep the data structures for incoming voxel data @@ -61,16 +75,17 @@ void AvatarVoxelSystem::init() { glBufferData(GL_ARRAY_BUFFER, BONE_ELEMENTS_PER_VOXEL * sizeof(GLfloat) * _maxVoxels, NULL, GL_DYNAMIC_DRAW); // load our skin program if this is the first avatar system to initialize - if (_skinProgram != 0) { - return; + if (!_skinProgramInitialized) { + _skinProgram.addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/skin_voxels.vert"); + _skinProgram.link(); + _skinProgramInitialized = true; } - _skinProgram = new ProgramObject(); - _skinProgram->addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/skin_voxels.vert"); - _skinProgram->link(); - _boneMatricesLocation = _skinProgram->uniformLocation("boneMatrices"); - _boneIndicesLocation = _skinProgram->attributeLocation("boneIndices"); - _boneWeightsLocation = _skinProgram->attributeLocation("boneWeights"); + _boneMatricesLocation = _skinProgram.uniformLocation("boneMatrices"); + _boneIndicesLocation = _skinProgram.attributeLocation("boneIndices"); + _boneWeightsLocation = _skinProgram.attributeLocation("boneWeights"); + + _initialized = true; } void AvatarVoxelSystem::removeOutOfView() { @@ -202,7 +217,7 @@ void AvatarVoxelSystem::updateVBOSegment(glBufferIndex segmentStart, glBufferInd } void AvatarVoxelSystem::applyScaleAndBindProgram(bool texture) { - _skinProgram->bind(); + _skinProgram.bind(); // the base matrix includes centering and scale QMatrix4x4 baseMatrix; @@ -222,21 +237,21 @@ void AvatarVoxelSystem::applyScaleAndBindProgram(bool texture) { boneMatrices[i].translate(-bindPosition.x, -bindPosition.y, -bindPosition.z); boneMatrices[i] *= baseMatrix; } - _skinProgram->setUniformValueArray(_boneMatricesLocation, boneMatrices, NUM_AVATAR_JOINTS); + _skinProgram.setUniformValueArray(_boneMatricesLocation, boneMatrices, NUM_AVATAR_JOINTS); glBindBuffer(GL_ARRAY_BUFFER, _vboBoneIndicesID); glVertexAttribPointer(_boneIndicesLocation, BONE_ELEMENTS_PER_VERTEX, GL_UNSIGNED_BYTE, false, 0, 0); - _skinProgram->enableAttributeArray(_boneIndicesLocation); + _skinProgram.enableAttributeArray(_boneIndicesLocation); glBindBuffer(GL_ARRAY_BUFFER, _vboBoneWeightsID); - _skinProgram->setAttributeBuffer(_boneWeightsLocation, GL_FLOAT, 0, BONE_ELEMENTS_PER_VERTEX); - _skinProgram->enableAttributeArray(_boneWeightsLocation); + _skinProgram.setAttributeBuffer(_boneWeightsLocation, GL_FLOAT, 0, BONE_ELEMENTS_PER_VERTEX); + _skinProgram.enableAttributeArray(_boneWeightsLocation); } void AvatarVoxelSystem::removeScaleAndReleaseProgram(bool texture) { - _skinProgram->release(); - _skinProgram->disableAttributeArray(_boneIndicesLocation); - _skinProgram->disableAttributeArray(_boneWeightsLocation); + _skinProgram.release(); + _skinProgram.disableAttributeArray(_boneIndicesLocation); + _skinProgram.disableAttributeArray(_boneWeightsLocation); } void AvatarVoxelSystem::handleVoxelDownloadProgress(qint64 bytesReceived, qint64 bytesTotal) { diff --git a/interface/src/avatar/AvatarVoxelSystem.h b/interface/src/avatar/AvatarVoxelSystem.h index 3a7cb224a6..bf95b774c3 100644 --- a/interface/src/avatar/AvatarVoxelSystem.h +++ b/interface/src/avatar/AvatarVoxelSystem.h @@ -58,6 +58,7 @@ private: void computeBoneIndicesAndWeights(const glm::vec3& vertex, BoneIndices& indices, glm::vec4& weights) const; + bool _initialized; int _mode; Avatar* _avatar; @@ -74,7 +75,8 @@ private: QNetworkReply* _voxelReply; - static ProgramObject* _skinProgram; + static bool _skinProgramInitialized; + static ProgramObject _skinProgram; static int _boneMatricesLocation; static int _boneIndicesLocation; static int _boneWeightsLocation; diff --git a/interface/src/avatar/Face.cpp b/interface/src/avatar/Face.cpp index 5bcfba2334..cc9b90ad4a 100644 --- a/interface/src/avatar/Face.cpp +++ b/interface/src/avatar/Face.cpp @@ -22,9 +22,10 @@ using namespace cv; -ProgramObject* Face::_videoProgram = 0; +bool Face::_initialized = false; +ProgramObject Face::_videoProgram; Face::Locations Face::_videoProgramLocations; -ProgramObject* Face::_texturedProgram = 0; +ProgramObject Face::_texturedProgram; Face::Locations Face::_texturedProgramLocations; GLuint Face::_vboID; GLuint Face::_iboID; @@ -53,6 +54,9 @@ Face::~Face() { glDeleteTextures(1, &_depthTextureID); } } + + glDeleteBuffers(1, &_vboID); + glDeleteBuffers(1, &_iboID); } void Face::setFrameFromWebcam() { @@ -293,9 +297,9 @@ bool Face::render(float alpha) { const int INDICES_PER_TRIANGLE = 3; const int INDEX_COUNT = QUAD_COUNT * TRIANGLES_PER_QUAD * INDICES_PER_TRIANGLE; - if (_videoProgram == 0) { - _videoProgram = loadProgram(QString(), "colorTexture", _videoProgramLocations); - _texturedProgram = loadProgram("_textured", "permutationNormalTexture", _texturedProgramLocations); + if (!_initialized) { + loadProgram(_videoProgram, QString(), "colorTexture", _videoProgramLocations); + loadProgram(_texturedProgram, "_textured", "permutationNormalTexture", _texturedProgramLocations); glGenBuffers(1, &_vboID); glBindBuffer(GL_ARRAY_BUFFER, _vboID); @@ -327,7 +331,8 @@ bool Face::render(float alpha) { } glBufferData(GL_ELEMENT_ARRAY_BUFFER, INDEX_COUNT * sizeof(int), indices, GL_STATIC_DRAW); delete[] indices; - + + _initialized = true; } else { glBindBuffer(GL_ARRAY_BUFFER, _vboID); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iboID); @@ -336,14 +341,14 @@ bool Face::render(float alpha) { glActiveTexture(GL_TEXTURE1); - ProgramObject* program = _videoProgram; + ProgramObject* program = &_videoProgram; Locations* locations = &_videoProgramLocations; if (_colorTextureID != 0) { glBindTexture(GL_TEXTURE_2D, _colorTextureID); } else { glBindTexture(GL_TEXTURE_2D, Application::getInstance()->getTextureCache()->getPermutationNormalTextureID()); - program = _texturedProgram; + program = &_texturedProgram; locations = &_texturedProgramLocations; } program->bind(); @@ -467,20 +472,17 @@ void Face::destroyCodecs() { } } -ProgramObject* Face::loadProgram(const QString& suffix, const char* secondTextureUniform, Locations& locations) { - ProgramObject* program = new ProgramObject(); - program->addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/face" + suffix + ".vert"); - program->addShaderFromSourceFile(QGLShader::Fragment, "resources/shaders/face" + suffix + ".frag"); - program->link(); +void Face::loadProgram(ProgramObject& program, const QString& suffix, const char* secondTextureUniform, Locations& locations) { + program.addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/face" + suffix + ".vert"); + program.addShaderFromSourceFile(QGLShader::Fragment, "resources/shaders/face" + suffix + ".frag"); + program.link(); - program->bind(); - program->setUniformValue("depthTexture", 0); - program->setUniformValue(secondTextureUniform, 1); - program->release(); + program.bind(); + program.setUniformValue("depthTexture", 0); + program.setUniformValue(secondTextureUniform, 1); + program.release(); - locations.texCoordCorner = program->uniformLocation("texCoordCorner"); - locations.texCoordRight = program->uniformLocation("texCoordRight"); - locations.texCoordUp = program->uniformLocation("texCoordUp"); - - return program; + locations.texCoordCorner = program.uniformLocation("texCoordCorner"); + locations.texCoordRight = program.uniformLocation("texCoordRight"); + locations.texCoordUp = program.uniformLocation("texCoordUp"); } diff --git a/interface/src/avatar/Face.h b/interface/src/avatar/Face.h index 1a68f8173e..20dfe74a0c 100644 --- a/interface/src/avatar/Face.h +++ b/interface/src/avatar/Face.h @@ -77,12 +77,14 @@ private: int texCoordUp; }; - static ProgramObject* loadProgram(const QString& suffix, const char* secondTextureUniform, Locations& locations); + static void loadProgram(ProgramObject& progam, const QString& suffix, const char* secondTextureUniform, Locations& locations); - static ProgramObject* _videoProgram; + static bool _initialized; + + static ProgramObject _videoProgram; static Locations _videoProgramLocations; - static ProgramObject* _texturedProgram; + static ProgramObject _texturedProgram; static Locations _texturedProgramLocations; static GLuint _vboID; diff --git a/interface/src/avatar/Head.cpp b/interface/src/avatar/Head.cpp index 7ee9a7f245..4f3ecf2db8 100644 --- a/interface/src/avatar/Head.cpp +++ b/interface/src/avatar/Head.cpp @@ -18,7 +18,6 @@ using namespace std; -const int MOHAWK_TRIANGLES = 50; const bool USING_PHYSICAL_MOHAWK = true; const float EYE_RIGHT_OFFSET = 0.27f; const float EYE_UP_OFFSET = 0.36f; @@ -47,7 +46,8 @@ const float IRIS_RADIUS = 0.007; const float IRIS_PROTRUSION = 0.0145f; const char IRIS_TEXTURE_FILENAME[] = "resources/images/iris.png"; -ProgramObject* Head::_irisProgram = 0; +bool Head::_irisProgramInitialized = false; +ProgramObject Head::_irisProgram; GLuint Head::_irisTextureID; int Head::_eyePositionLocation; @@ -76,8 +76,7 @@ Head::Head(Avatar* owningAvatar) : _returnSpringScale(1.0f), _bodyRotation(0.0f, 0.0f, 0.0f), _renderLookatVectors(false), - _mohawkTriangleFan(NULL), - _mohawkColors(NULL), + _mohawkInitialized(false), _saccade(0.0f, 0.0f, 0.0f), _saccadeTarget(0.0f, 0.0f, 0.0f), _leftEyeBlink(0.0f), @@ -99,16 +98,15 @@ Head::Head(Avatar* owningAvatar) : } void Head::init() { - if (_irisProgram == 0) { + if (!_irisProgramInitialized) { switchToResourcesParentIfRequired(); - _irisProgram = new ProgramObject(); - _irisProgram->addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/iris.vert"); - _irisProgram->addShaderFromSourceFile(QGLShader::Fragment, "resources/shaders/iris.frag"); - _irisProgram->link(); - - _irisProgram->setUniformValue("texture", 0); - _eyePositionLocation = _irisProgram->uniformLocation("eyePosition"); - + _irisProgram.addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/iris.vert"); + _irisProgram.addShaderFromSourceFile(QGLShader::Fragment, "resources/shaders/iris.frag"); + _irisProgram.link(); + + _irisProgram.setUniformValue("texture", 0); + _eyePositionLocation = _irisProgram.uniformLocation("eyePosition"); + QImage image = QImage(IRIS_TEXTURE_FILENAME).convertToFormat(QImage::Format_ARGB32); glGenTextures(1, &_irisTextureID); @@ -118,6 +116,8 @@ void Head::init() { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glBindTexture(GL_TEXTURE_2D, 0); + + _irisProgramInitialized = true; } } @@ -334,9 +334,7 @@ void Head::render(float alpha) { void Head::setScale (float scale) { _scale = scale; - - delete[] _mohawkTriangleFan; - delete[] _mohawkColors; + createMohawk(); if (USING_PHYSICAL_MOHAWK) { @@ -363,8 +361,6 @@ void Head::createMohawk() { float height = _scale * (0.08f + randFloat() * 0.05f); float variance = 0.03 + randFloat() * 0.03f; const float RAD_PER_TRIANGLE = (2.3f + randFloat() * 0.2f) / (float)MOHAWK_TRIANGLES; - _mohawkTriangleFan = new glm::vec3[MOHAWK_TRIANGLES]; - _mohawkColors = new glm::vec3[MOHAWK_TRIANGLES]; _mohawkTriangleFan[0] = glm::vec3(0, 0, 0); glm::vec3 basicColor(randFloat(), randFloat(), randFloat()); _mohawkColors[0] = basicColor; @@ -382,14 +378,9 @@ void Head::createMohawk() { void Head::renderMohawk() { - if (!_mohawkTriangleFan) { + if (!_mohawkInitialized) { createMohawk(); - - // if we get here and still don't have a mohawk then we don't know who we are - // so return out since we can't render it yet - if (!_mohawkTriangleFan) { - return; - } + _mohawkInitialized = true; } if (USING_PHYSICAL_MOHAWK) { @@ -649,7 +640,7 @@ void Head::renderEyeBalls() { glutSolidSphere(_scale * EYEBALL_RADIUS, 30, 30); glPopMatrix(); - _irisProgram->bind(); + _irisProgram.bind(); glBindTexture(GL_TEXTURE_2D, _irisTextureID); glEnable(GL_TEXTURE_2D); @@ -671,7 +662,7 @@ void Head::renderEyeBalls() { _scale * IRIS_RADIUS); // flatten the iris // this ugliness is simply to invert the model transform and get the eye position in model space - _irisProgram->setUniform(_eyePositionLocation, (glm::inverse(rotation) * + _irisProgram.setUniform(_eyePositionLocation, (glm::inverse(rotation) * (Application::getInstance()->getCamera()->getPosition() - _leftEyePosition) + glm::vec3(0.0f, 0.0f, _scale * IRIS_PROTRUSION)) * glm::vec3(1.0f / (_scale * IRIS_RADIUS * 2.0f), 1.0f / (_scale * IRIS_RADIUS * 2.0f), 1.0f / (_scale * IRIS_RADIUS))); @@ -695,7 +686,7 @@ void Head::renderEyeBalls() { _scale * IRIS_RADIUS); // flatten the iris // this ugliness is simply to invert the model transform and get the eye position in model space - _irisProgram->setUniform(_eyePositionLocation, (glm::inverse(rotation) * + _irisProgram.setUniform(_eyePositionLocation, (glm::inverse(rotation) * (Application::getInstance()->getCamera()->getPosition() - _rightEyePosition) + glm::vec3(0.0f, 0.0f, _scale * IRIS_PROTRUSION)) * glm::vec3(1.0f / (_scale * IRIS_RADIUS * 2.0f), 1.0f / (_scale * IRIS_RADIUS * 2.0f), 1.0f / (_scale * IRIS_RADIUS))); @@ -704,7 +695,7 @@ void Head::renderEyeBalls() { } glPopMatrix(); - _irisProgram->release(); + _irisProgram.release(); glBindTexture(GL_TEXTURE_2D, 0); glDisable(GL_TEXTURE_2D); diff --git a/interface/src/avatar/Head.h b/interface/src/avatar/Head.h index c6fcac0bd7..fdd3de522c 100644 --- a/interface/src/avatar/Head.h +++ b/interface/src/avatar/Head.h @@ -29,6 +29,7 @@ enum eyeContactTargets { MOUTH }; +const int MOHAWK_TRIANGLES = 50; const int NUM_HAIR_TUFTS = 4; class Avatar; @@ -71,7 +72,7 @@ public: Face& getFace() { return _face; } const bool getReturnToCenter() const { return _returnHeadToCenter; } // Do you want head to try to return to center (depends on interface detected) - float getAverageLoudness() {return _averageLoudness;}; + float getAverageLoudness() {return _averageLoudness;} glm::vec3 calculateAverageEyePosition() { return _leftEyePosition + (_rightEyePosition - _leftEyePosition ) * ONE_HALF; } float yawRate; @@ -87,7 +88,7 @@ private: glm::vec3 right; glm::vec3 front; }; - + float _renderAlpha; bool _returnHeadToCenter; glm::vec3 _skinColor; @@ -112,8 +113,9 @@ private: glm::vec3 _bodyRotation; bool _renderLookatVectors; BendyLine _hairTuft[NUM_HAIR_TUFTS]; - glm::vec3* _mohawkTriangleFan; - glm::vec3* _mohawkColors; + bool _mohawkInitialized; + glm::vec3 _mohawkTriangleFan[MOHAWK_TRIANGLES]; + glm::vec3 _mohawkColors[MOHAWK_TRIANGLES]; glm::vec3 _saccade; glm::vec3 _saccadeTarget; float _leftEyeBlink; @@ -129,7 +131,8 @@ private: float _cameraFollowHeadRate; Face _face; - static ProgramObject* _irisProgram; + static bool _irisProgramInitialized; + static ProgramObject _irisProgram; static GLuint _irisTextureID; static int _eyePositionLocation; diff --git a/libraries/shared/src/NodeList.h b/libraries/shared/src/NodeList.h index 6f0e6827e9..669e82da13 100644 --- a/libraries/shared/src/NodeList.h +++ b/libraries/shared/src/NodeList.h @@ -67,7 +67,7 @@ public: NODE_TYPE getOwnerType() const { return _ownerType; } void setOwnerType(NODE_TYPE ownerType) { _ownerType = ownerType; } - const char* getDomainHostname() const { return _domainHostname; }; + const char* getDomainHostname() const { return _domainHostname; } void setDomainHostname(const char* domainHostname); void setDomainIP(const char* domainIP); @@ -81,7 +81,7 @@ public: UDPSocket* getNodeSocket() { return &_nodeSocket; } - unsigned short int getSocketListenPort() const { return _nodeSocket.getListeningPort(); }; + unsigned short int getSocketListenPort() const { return _nodeSocket.getListeningPort(); } void(*linkedDataCreateCallback)(Node *); From 7688dc4779ccde1eb321bec80ee512ee482b5829 Mon Sep 17 00:00:00 2001 From: atlante45 Date: Tue, 3 Sep 2013 13:50:01 -0700 Subject: [PATCH 2/7] Fixed renderer related files memory wastes --- interface/src/avatar/Head.cpp | 4 ++++ interface/src/avatar/Head.h | 1 + interface/src/renderer/GlowEffect.cpp | 28 ++++++++++++++++++++++++--- interface/src/renderer/GlowEffect.h | 4 +++- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/interface/src/avatar/Head.cpp b/interface/src/avatar/Head.cpp index 4f3ecf2db8..20c4c6c816 100644 --- a/interface/src/avatar/Head.cpp +++ b/interface/src/avatar/Head.cpp @@ -97,6 +97,10 @@ Head::Head(Avatar* owningAvatar) : } } +Head::~Head() { + glDeleteTextures(1, &_irisTextureID); +} + void Head::init() { if (!_irisProgramInitialized) { switchToResourcesParentIfRequired(); diff --git a/interface/src/avatar/Head.h b/interface/src/avatar/Head.h index fdd3de522c..0952de0252 100644 --- a/interface/src/avatar/Head.h +++ b/interface/src/avatar/Head.h @@ -38,6 +38,7 @@ class ProgramObject; class Head : public HeadData { public: Head(Avatar* owningAvatar); + ~Head(); void init(); void reset(); diff --git a/interface/src/renderer/GlowEffect.cpp b/interface/src/renderer/GlowEffect.cpp index 24936b85d3..fc95ed24d6 100644 --- a/interface/src/renderer/GlowEffect.cpp +++ b/interface/src/renderer/GlowEffect.cpp @@ -15,13 +15,28 @@ #include "ProgramObject.h" #include "RenderUtil.h" -GlowEffect::GlowEffect() : _renderMode(DIFFUSE_ADD_MODE), _isOddFrame(false), _intensity(0.0f) { +GlowEffect::GlowEffect() + : _initialized(false), + _renderMode(DIFFUSE_ADD_MODE), + _isOddFrame(false), + _intensity(0.0f) { +} + +GlowEffect::~GlowEffect() { + if (_initialized) { + delete _addProgram; + delete _horizontalBlurProgram; + delete _verticalBlurAddProgram; + delete _verticalBlurProgram; + delete _addSeparateProgram; + delete _diffuseProgram; + } } QOpenGLFramebufferObject* GlowEffect::getFreeFramebufferObject() const { return (_renderMode == DIFFUSE_ADD_MODE && !_isOddFrame) ? - Application::getInstance()->getTextureCache()->getTertiaryFramebufferObject() : - Application::getInstance()->getTextureCache()->getSecondaryFramebufferObject(); + Application::getInstance()->getTextureCache()->getTertiaryFramebufferObject() : + Application::getInstance()->getTextureCache()->getSecondaryFramebufferObject(); } static ProgramObject* createProgram(const QString& name) { @@ -37,6 +52,11 @@ static ProgramObject* createProgram(const QString& name) { } void GlowEffect::init() { + if (_initialized) { + qDebug("[ERROR] GlowEffeect is already initialized.\n"); + return; + } + switchToResourcesParentIfRequired(); _addProgram = createProgram("glow_add"); @@ -59,6 +79,8 @@ void GlowEffect::init() { _diffuseProgram->release(); _diffusionScaleLocation = _diffuseProgram->uniformLocation("diffusionScale"); + + _initialized = true; } void GlowEffect::prepare() { diff --git a/interface/src/renderer/GlowEffect.h b/interface/src/renderer/GlowEffect.h index 37765d18ba..8168ae4374 100644 --- a/interface/src/renderer/GlowEffect.h +++ b/interface/src/renderer/GlowEffect.h @@ -21,8 +21,8 @@ class GlowEffect : public QObject { Q_OBJECT public: - GlowEffect(); + ~GlowEffect(); /// Returns a pointer to the framebuffer object that the glow effect is *not* using for persistent state /// (either the secondary or the tertiary). @@ -53,6 +53,8 @@ private: enum RenderMode { ADD_MODE, BLUR_ADD_MODE, BLUR_PERSIST_ADD_MODE, DIFFUSE_ADD_MODE, RENDER_MODE_COUNT }; + bool _initialized; + RenderMode _renderMode; ProgramObject* _addProgram; ProgramObject* _horizontalBlurProgram; From 06119990e8d4ea569c617facf45e4f245a36edae Mon Sep 17 00:00:00 2001 From: atlante45 Date: Tue, 3 Sep 2013 14:47:50 -0700 Subject: [PATCH 3/7] Fixed ui related files memory wastes --- interface/src/VoxelSystem.cpp | 36 ++++++++++++++++----------- interface/src/renderer/TextureCache.h | 4 +-- interface/src/ui/BandwidthDialog.cpp | 6 +++++ interface/src/ui/BandwidthDialog.h | 2 +- interface/src/ui/VoxelStatsDialog.cpp | 6 +++++ interface/src/ui/VoxelStatsDialog.h | 1 + 6 files changed, 38 insertions(+), 17 deletions(-) diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index c8df22b270..5229873164 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -51,8 +51,12 @@ GLubyte identityIndices[] = { 0,2,1, 0,3,2, // Z- 10,11,15, 10,15,14, // Y+ 4,5,6, 4,6,7 }; // Z+ -VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) : - NodeData(NULL), _treeScale(treeScale), _maxVoxels(maxVoxels) { +VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) + : NodeData(NULL), + _treeScale(treeScale), + _maxVoxels(maxVoxels), + _initialized(false) { + _voxelsInReadArrays = _voxelsInWriteArrays = _voxelsUpdated = 0; _writeRenderFullVBO = true; _readRenderFullVBO = true; @@ -115,22 +119,25 @@ void VoxelSystem::clearFreeBufferIndexes() { } VoxelSystem::~VoxelSystem() { - delete[] _readVerticesArray; - delete[] _writeVerticesArray; - delete[] _readColorsArray; - delete[] _writeColorsArray; - delete[] _writeVoxelDirtyArray; - delete[] _readVoxelDirtyArray; + if (_initialized) { + // Destroy glBuffers + glDeleteBuffers(1, &_vboVerticesID); + glDeleteBuffers(1, &_vboNormalsID); + glDeleteBuffers(1, &_vboColorsID); + glDeleteBuffers(1, &_vboIndicesID); + + delete[] _readVerticesArray; + delete[] _writeVerticesArray; + delete[] _readColorsArray; + delete[] _writeColorsArray; + delete[] _writeVoxelDirtyArray; + delete[] _readVoxelDirtyArray; + } + delete _tree; pthread_mutex_destroy(&_bufferWriteLock); pthread_mutex_destroy(&_treeLock); - // Destroy glBuffers - glDeleteBuffers(1, &_vboVerticesID); - glDeleteBuffers(1, &_vboNormalsID); - glDeleteBuffers(1, &_vboColorsID); - glDeleteBuffers(1, &_vboIndicesID); - VoxelNode::removeDeleteHook(this); } @@ -639,6 +646,7 @@ void VoxelSystem::init() { _perlinModulateProgramInitialized = true; } + _initialized = true; } void VoxelSystem::updateFullVBOs() { diff --git a/interface/src/renderer/TextureCache.h b/interface/src/renderer/TextureCache.h index 9be048f398..50c495bfa3 100644 --- a/interface/src/renderer/TextureCache.h +++ b/interface/src/renderer/TextureCache.h @@ -49,9 +49,9 @@ private: QOpenGLFramebufferObject* createFramebufferObject(); GLuint _permutationNormalTextureID; - - QOpenGLFramebufferObject* _primaryFramebufferObject; + GLuint _primaryDepthTextureID; + QOpenGLFramebufferObject* _primaryFramebufferObject; QOpenGLFramebufferObject* _secondaryFramebufferObject; QOpenGLFramebufferObject* _tertiaryFramebufferObject; }; diff --git a/interface/src/ui/BandwidthDialog.cpp b/interface/src/ui/BandwidthDialog.cpp index 4ff9a9878e..5f7a73cc44 100644 --- a/interface/src/ui/BandwidthDialog.cpp +++ b/interface/src/ui/BandwidthDialog.cpp @@ -38,6 +38,12 @@ BandwidthDialog::BandwidthDialog(QWidget* parent, BandwidthMeter* model) : } } +BandwidthDialog::~BandwidthDialog() { + for (int i = 0; i < BandwidthMeter::N_STREAMS; ++i) { + delete _labels[i]; + } +} + void BandwidthDialog::paintEvent(QPaintEvent* event) { // Update labels diff --git a/interface/src/ui/BandwidthDialog.h b/interface/src/ui/BandwidthDialog.h index 636e91dce9..a702b1be23 100644 --- a/interface/src/ui/BandwidthDialog.h +++ b/interface/src/ui/BandwidthDialog.h @@ -18,9 +18,9 @@ class BandwidthDialog : public QDialog { Q_OBJECT public: - // Sets up the UI based on the configuration of the BandwidthMeter BandwidthDialog(QWidget* parent, BandwidthMeter* model); + ~BandwidthDialog(); signals: diff --git a/interface/src/ui/VoxelStatsDialog.cpp b/interface/src/ui/VoxelStatsDialog.cpp index 52b32ef7a5..5892c2c70e 100644 --- a/interface/src/ui/VoxelStatsDialog.cpp +++ b/interface/src/ui/VoxelStatsDialog.cpp @@ -53,6 +53,12 @@ VoxelStatsDialog::VoxelStatsDialog(QWidget* parent, VoxelSceneStats* model) : } } +VoxelStatsDialog::~VoxelStatsDialog() { + for (int i = 0; i <(int)VoxelSceneStats::ITEM_COUNT; ++i) { + delete _labels[i]; + } +} + void VoxelStatsDialog::paintEvent(QPaintEvent* event) { // Update labels diff --git a/interface/src/ui/VoxelStatsDialog.h b/interface/src/ui/VoxelStatsDialog.h index eab5b6a45a..474f65a1e3 100644 --- a/interface/src/ui/VoxelStatsDialog.h +++ b/interface/src/ui/VoxelStatsDialog.h @@ -19,6 +19,7 @@ class VoxelStatsDialog : public QDialog { public: // Sets up the UI VoxelStatsDialog(QWidget* parent, VoxelSceneStats* model); + ~VoxelStatsDialog(); signals: void closed(); From b03482ead50a50b0c6ff956da9df241cbd185fb1 Mon Sep 17 00:00:00 2001 From: atlante45 Date: Tue, 3 Sep 2013 17:16:06 -0700 Subject: [PATCH 4/7] Some more memory leaks and codes formatting --- interface/src/Audio.h | 16 +++--- interface/src/Environment.cpp | 18 +++++++ interface/src/Environment.h | 3 ++ interface/src/Menu.cpp | 19 +++++-- interface/src/Menu.h | 1 + interface/src/Transmitter.cpp | 6 +++ interface/src/Transmitter.h | 1 + interface/src/starfield/Controller.h | 4 ++ libraries/avatars/src/AvatarData.h | 6 +-- libraries/shared/src/NetworkPacket.h | 10 ++-- libraries/shared/src/Node.h | 8 +-- libraries/shared/src/NodeList.h | 4 +- libraries/shared/src/PerfStat.h | 6 +-- libraries/shared/src/PointerStack.h | 14 ++--- libraries/shared/src/SharedUtil.h | 2 +- libraries/shared/src/StdDev.h | 2 +- libraries/voxels/src/Tags.cpp | 8 +++ libraries/voxels/src/Tags.h | 2 + libraries/voxels/src/VoxelNode.h | 56 ++++++++++---------- libraries/voxels/src/VoxelNodeBag.h | 4 +- libraries/voxels/src/VoxelProjectedPolygon.h | 36 ++++++------- libraries/voxels/src/VoxelSceneStats.h | 2 +- libraries/voxels/src/VoxelTree.h | 8 +-- 23 files changed, 145 insertions(+), 91 deletions(-) diff --git a/interface/src/Audio.h b/interface/src/Audio.h index 8d6371a6f9..c9fc8402e7 100644 --- a/interface/src/Audio.h +++ b/interface/src/Audio.h @@ -40,19 +40,19 @@ public: void addReceivedAudioToBuffer(unsigned char* receivedData, int receivedBytes); - float getLastInputLoudness() const { return _lastInputLoudness; }; + float getLastInputLoudness() const { return _lastInputLoudness; } - void setLastAcceleration(glm::vec3 lastAcceleration) { _lastAcceleration = lastAcceleration; }; - void setLastVelocity(glm::vec3 lastVelocity) { _lastVelocity = lastVelocity; }; + void setLastAcceleration(glm::vec3 lastAcceleration) { _lastAcceleration = lastAcceleration; } + void setLastVelocity(glm::vec3 lastVelocity) { _lastVelocity = lastVelocity; } - void setJitterBufferSamples(int samples) { _jitterBufferSamples = samples; }; - int getJitterBufferSamples() { return _jitterBufferSamples; }; + void setJitterBufferSamples(int samples) { _jitterBufferSamples = samples; } + int getJitterBufferSamples() { return _jitterBufferSamples; } void lowPassFilter(int16_t* inputBuffer); void startCollisionSound(float magnitude, float frequency, float noise, float duration); - float getCollisionSoundMagnitude() { return _collisionSoundMagnitude; }; + float getCollisionSoundMagnitude() { return _collisionSoundMagnitude; } void ping(); @@ -61,8 +61,8 @@ public: // The results of the analysis are written to the log. bool eventuallyAnalyzePing(); - void setListenMode(AudioRingBuffer::ListenMode mode) { _listenMode = mode; }; - void setListenRadius(float radius) { _listenRadius = radius; }; + void setListenMode(AudioRingBuffer::ListenMode mode) { _listenMode = mode; } + void setListenRadius(float radius) { _listenRadius = radius; } void addListenSource(int sourceID); void removeListenSource(int sourceID); void clearListenSources(); diff --git a/interface/src/Environment.cpp b/interface/src/Environment.cpp index adfb1cfb3b..4f4e694713 100644 --- a/interface/src/Environment.cpp +++ b/interface/src/Environment.cpp @@ -38,13 +38,31 @@ static sockaddr getZeroAddress() { return addr; } +Environment::Environment() + : _initialized(false) { +} + +Environment::~Environment() { + if (_initialized) { + delete _skyFromAtmosphereProgram; + delete _skyFromSpaceProgram; + } +} + void Environment::init() { + if (_initialized) { + qDebug("[ERROR] Environment is already initialized.\n"); + return; + } + switchToResourcesParentIfRequired(); _skyFromAtmosphereProgram = createSkyProgram("Atmosphere", _skyFromAtmosphereUniformLocations); _skyFromSpaceProgram = createSkyProgram("Space", _skyFromSpaceUniformLocations); // start off with a default-constructed environment data _data[getZeroAddress()][0]; + + _initialized = true; } void Environment::resetToDefault() { diff --git a/interface/src/Environment.h b/interface/src/Environment.h index 7bdbfa600b..1095687ae0 100644 --- a/interface/src/Environment.h +++ b/interface/src/Environment.h @@ -22,6 +22,8 @@ class ProgramObject; class Environment { public: + Environment(); + ~Environment(); void init(); void resetToDefault(); @@ -40,6 +42,7 @@ private: void renderAtmosphere(Camera& camera, const EnvironmentData& data); + bool _initialized; ProgramObject* _skyFromAtmosphereProgram; ProgramObject* _skyFromSpaceProgram; diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 2b4b07f898..dc288fd73b 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -413,6 +413,13 @@ Menu::Menu() : addCheckableActionToQMenuAndActionHash(developerMenu, MenuOption::DestructiveAddVoxel); } +Menu::~Menu() { + qDebug("[DEBUG] Menu destructor.\n]"); + bandwidthDetailsClosed(); + voxelStatsDetailsClosed(); + delete _voxelModeActionsGroup; +} + void Menu::loadSettings(QSettings* settings) { if (!settings) { settings = Application::getInstance()->getSettings(); @@ -855,8 +862,10 @@ void Menu::bandwidthDetails() { } void Menu::bandwidthDetailsClosed() { - delete _bandwidthDialog; - _bandwidthDialog = NULL; + if (_bandwidthDialog) { + delete _bandwidthDialog; + _bandwidthDialog = NULL; + } } void Menu::voxelStatsDetails() { @@ -870,8 +879,10 @@ void Menu::voxelStatsDetails() { } void Menu::voxelStatsDetailsClosed() { - delete _voxelStatsDialog; - _voxelStatsDialog = NULL; + if (_voxelStatsDialog) { + delete _voxelStatsDialog; + _voxelStatsDialog = NULL; + } } void Menu::cycleFrustumRenderMode() { diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 7a796e1aa9..e207ffe32d 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -79,6 +79,7 @@ private: static Menu* _instance; Menu(); + ~Menu(); typedef void(*settingsAction)(QSettings*, QAction*); static void loadAction(QSettings* set, QAction* action); diff --git a/interface/src/Transmitter.cpp b/interface/src/Transmitter.cpp index eac769ead7..c82b018ec4 100644 --- a/interface/src/Transmitter.cpp +++ b/interface/src/Transmitter.cpp @@ -29,6 +29,12 @@ Transmitter::Transmitter() : } +Transmitter::~Transmitter() { + if (_lastReceivedPacket) { + delete _lastReceivedPacket; + } +} + void Transmitter::checkForLostTransmitter() { // If we are in motion, check for loss of transmitter packets if (glm::length(_estimatedRotation) > 0.f) { diff --git a/interface/src/Transmitter.h b/interface/src/Transmitter.h index 27426e1d27..b35d7200bd 100644 --- a/interface/src/Transmitter.h +++ b/interface/src/Transmitter.h @@ -25,6 +25,7 @@ class Transmitter { public: Transmitter(); + ~Transmitter(); void render(); void checkForLostTransmitter(); void resetLevels(); diff --git a/interface/src/starfield/Controller.h b/interface/src/starfield/Controller.h index cefe46664e..186a23c742 100644 --- a/interface/src/starfield/Controller.h +++ b/interface/src/starfield/Controller.h @@ -70,6 +70,10 @@ namespace starfield { _renderer(0l) { } + ~Controller() { + delete _renderer; + } + #if !STARFIELD_MULTITHREADING #define lock #define _(x) diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index db328053c0..2179cb3c4d 100755 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -78,11 +78,11 @@ public: // Hand State - void setHandState(char s) { _handState = s; }; - char getHandState() const {return _handState; }; + void setHandState(char s) { _handState = s; } + char getHandState() const {return _handState; } // getters for camera details - const glm::vec3& getCameraPosition() const { return _cameraPosition; }; + const glm::vec3& getCameraPosition() const { return _cameraPosition; } const glm::quat& getCameraOrientation() const { return _cameraOrientation; } float getCameraFov() const { return _cameraFov; } float getCameraAspectRatio() const { return _cameraAspectRatio; } diff --git a/libraries/shared/src/NetworkPacket.h b/libraries/shared/src/NetworkPacket.h index 01bced6a71..8017f7057e 100644 --- a/libraries/shared/src/NetworkPacket.h +++ b/libraries/shared/src/NetworkPacket.h @@ -32,12 +32,12 @@ public: NetworkPacket(sockaddr& address, unsigned char* packetData, ssize_t packetLength); - sockaddr& getAddress() { return _address; }; - ssize_t getLength() const { return _packetLength; }; - unsigned char* getData() { return &_packetData[0]; }; + sockaddr& getAddress() { return _address; } + ssize_t getLength() const { return _packetLength; } + unsigned char* getData() { return &_packetData[0]; } - const sockaddr& getAddress() const { return _address; }; - const unsigned char* getData() const { return &_packetData[0]; }; + const sockaddr& getAddress() const { return _address; } + const unsigned char* getData() const { return &_packetData[0]; } private: void copyContents(const sockaddr& address, const unsigned char* packetData, ssize_t packetLength); diff --git a/libraries/shared/src/Node.h b/libraries/shared/src/Node.h index df20664bda..2de75bcec1 100644 --- a/libraries/shared/src/Node.h +++ b/libraries/shared/src/Node.h @@ -58,15 +58,15 @@ public: NodeData* getLinkedData() const { return _linkedData; } void setLinkedData(NodeData* linkedData) { _linkedData = linkedData; } - bool isAlive() const { return _isAlive; }; - void setAlive(bool isAlive) { _isAlive = isAlive; }; + bool isAlive() const { return _isAlive; } + void setAlive(bool isAlive) { _isAlive = isAlive; } void recordBytesReceived(int bytesReceived); float getAverageKilobitsPerSecond(); float getAveragePacketsPerSecond(); - int getPingMs() const { return _pingMs; }; - void setPingMs(int pingMs) { _pingMs = pingMs; }; + int getPingMs() const { return _pingMs; } + void setPingMs(int pingMs) { _pingMs = pingMs; } void lock() { pthread_mutex_lock(&_mutex); } void unlock() { pthread_mutex_unlock(&_mutex); } diff --git a/libraries/shared/src/NodeList.h b/libraries/shared/src/NodeList.h index 669e82da13..b76eab9da0 100644 --- a/libraries/shared/src/NodeList.h +++ b/libraries/shared/src/NodeList.h @@ -156,9 +156,9 @@ private: class NodeListIterator : public std::iterator { public: NodeListIterator(const NodeList* nodeList, int nodeIndex); - ~NodeListIterator() {}; + ~NodeListIterator() {} - int getNodeIndex() { return _nodeIndex; }; + int getNodeIndex() { return _nodeIndex; } NodeListIterator& operator=(const NodeListIterator& otherValue); diff --git a/libraries/shared/src/PerfStat.h b/libraries/shared/src/PerfStat.h index 22eb5d38b5..320da3d280 100644 --- a/libraries/shared/src/PerfStat.h +++ b/libraries/shared/src/PerfStat.h @@ -35,9 +35,9 @@ private: public: std::string group; - PerfStatHistory(): count(0), totalTime(0.0) {}; + PerfStatHistory(): count(0), totalTime(0.0) {} PerfStatHistory(std::string myGroup, double initialTime, long int initialCount) : - count(initialCount), totalTime(initialTime), group(myGroup) {}; + count(initialCount), totalTime(initialTime), group(myGroup) {} void recordTime(double thisTime) { totalTime+=thisTime; @@ -94,7 +94,7 @@ public: _start(usecTimestampNow()), _message(message), _renderWarningsOn(renderWarnings), - _alwaysDisplay(alwaysDisplay) { }; + _alwaysDisplay(alwaysDisplay) { } ~PerformanceWarning(); }; diff --git a/libraries/shared/src/PointerStack.h b/libraries/shared/src/PointerStack.h index a9066c54fc..1626db3a3b 100644 --- a/libraries/shared/src/PointerStack.h +++ b/libraries/shared/src/PointerStack.h @@ -18,7 +18,7 @@ public: PointerStack() : _elements(NULL), _elementsInUse(0), - _sizeOfElementsArray(0) {}; + _sizeOfElementsArray(0) {} ~PointerStack(); @@ -28,7 +28,7 @@ public: } _elements[_elementsInUse] = element; _elementsInUse++; - }; + } void* pop() { if (_elementsInUse) { @@ -39,14 +39,14 @@ public: return element; } return NULL; - }; + } void* top() const { return (_elementsInUse) ? _elements[_elementsInUse - 1] : NULL; } - bool isEmpty() const { return (_elementsInUse == 0); }; - bool empty() const { return (_elementsInUse == 0); }; - int count() const { return _elementsInUse; }; - int size() const { return _elementsInUse; }; + bool isEmpty() const { return (_elementsInUse == 0); } + bool empty() const { return (_elementsInUse == 0); } + int count() const { return _elementsInUse; } + int size() const { return _elementsInUse; } private: void growAndPush(void* element); diff --git a/libraries/shared/src/SharedUtil.h b/libraries/shared/src/SharedUtil.h index 32553b967b..82850d8de3 100644 --- a/libraries/shared/src/SharedUtil.h +++ b/libraries/shared/src/SharedUtil.h @@ -106,7 +106,7 @@ int removeFromSortedArrays(void* value, void** valueArray, float* keyArray, int* // Helper Class for debugging class debug { public: - static const char* valueOf(bool checkValue) { return checkValue ? "yes" : "no"; }; + static const char* valueOf(bool checkValue) { return checkValue ? "yes" : "no"; } }; #endif /* defined(__hifi__SharedUtil__) */ diff --git a/libraries/shared/src/StdDev.h b/libraries/shared/src/StdDev.h index ca13b67a61..74937f6f9a 100644 --- a/libraries/shared/src/StdDev.h +++ b/libraries/shared/src/StdDev.h @@ -16,7 +16,7 @@ class StDev { void addValue(float v); float getAverage(); float getStDev(); - int getSamples() {return sampleCount;}; + int getSamples() {return sampleCount;} private: float * data; int sampleCount; diff --git a/libraries/voxels/src/Tags.cpp b/libraries/voxels/src/Tags.cpp index 32d717cc6b..ef0a2a1faf 100644 --- a/libraries/voxels/src/Tags.cpp +++ b/libraries/voxels/src/Tags.cpp @@ -108,6 +108,10 @@ TagList::TagList(std::stringstream &ss) : } } +TagList::~TagList() { + _data.clear(); +} + TagCompound::TagCompound(std::stringstream &ss) : Tag(TAG_Compound, ss), _size(0), @@ -145,6 +149,10 @@ TagCompound::TagCompound(std::stringstream &ss) : } } +TagCompound::~TagCompound() { + _data.clear(); +} + TagIntArray::TagIntArray(std::stringstream &ss) : Tag(TAG_Int_Array, ss) { _size = ss.get() << 24 | ss.get() << 16 | ss.get() << 8 | ss.get(); diff --git a/libraries/voxels/src/Tags.h b/libraries/voxels/src/Tags.h index 9888190b14..84aec00627 100644 --- a/libraries/voxels/src/Tags.h +++ b/libraries/voxels/src/Tags.h @@ -124,6 +124,7 @@ private: class TagList : public Tag { public: TagList(std::stringstream &ss); + ~TagList(); int getTagId() const {return _tagId;} int getSize () const {return _size; } @@ -138,6 +139,7 @@ private: class TagCompound : public Tag { public: TagCompound(std::stringstream &ss); + ~TagCompound(); int getSize () const {return _size; } std::list getData () const {return _data; } diff --git a/libraries/voxels/src/VoxelNode.h b/libraries/voxels/src/VoxelNode.h index 5035dbaad3..c98b26744c 100644 --- a/libraries/voxels/src/VoxelNode.h +++ b/libraries/voxels/src/VoxelNode.h @@ -34,8 +34,8 @@ public: VoxelNode(unsigned char * octalCode); // regular constructor ~VoxelNode(); - unsigned char* getOctalCode() const { return _octalCode; }; - VoxelNode* getChildAtIndex(int childIndex) const { return _children[childIndex]; }; + unsigned char* getOctalCode() const { return _octalCode; } + VoxelNode* getChildAtIndex(int childIndex) const { return _children[childIndex]; } void deleteChildAtIndex(int childIndex); VoxelNode* removeChildAtIndex(int childIndex); VoxelNode* addChildAtIndex(int childIndex); @@ -45,15 +45,15 @@ public: void setRandomColor(int minimumBrightness); bool collapseIdenticalLeaves(); - const AABox& getAABox() const { return _box; }; - const glm::vec3& getCenter() const { return _box.getCenter(); }; - const glm::vec3& getCorner() const { return _box.getCorner(); }; - float getScale() const { return _box.getSize().x; /* voxelScale = (1 / powf(2, *node->getOctalCode())); */ }; - int getLevel() const { return *_octalCode + 1; /* one based or zero based? this doesn't correctly handle 2 byte case */ }; + const AABox& getAABox() const { return _box; } + const glm::vec3& getCenter() const { return _box.getCenter(); } + const glm::vec3& getCorner() const { return _box.getCorner(); } + float getScale() const { return _box.getSize().x; } // voxelScale = (1 / powf(2, *node->getOctalCode())); } + int getLevel() const { return *_octalCode + 1; } // one based or zero based? this doesn't correctly handle 2 byte case float getEnclosingRadius() const; - bool isColored() const { return (_trueColor[3]==1); }; + bool isColored() const { return (_trueColor[3]==1); } bool isInView(const ViewFrustum& viewFrustum) const; ViewFrustum::location inFrustum(const ViewFrustum& viewFrustum) const; float distanceToCamera(const ViewFrustum& viewFrustum) const; @@ -68,18 +68,18 @@ public: bool isLeaf() const { return _childCount == 0; } int getChildCount() const { return _childCount; } void printDebugDetails(const char* label) const; - bool isDirty() const { return _isDirty; }; - void clearDirtyBit() { _isDirty = false; }; - bool hasChangedSince(uint64_t time) const { return (_lastChanged > time); }; - void markWithChangedTime() { _lastChanged = usecTimestampNow(); }; - uint64_t getLastChanged() const { return _lastChanged; }; + bool isDirty() const { return _isDirty; } + void clearDirtyBit() { _isDirty = false; } + bool hasChangedSince(uint64_t time) const { return (_lastChanged > time); } + void markWithChangedTime() { _lastChanged = usecTimestampNow(); } + uint64_t getLastChanged() const { return _lastChanged; } void handleSubtreeChanged(VoxelTree* myTree); - glBufferIndex getBufferIndex() const { return _glBufferIndex; }; - bool isKnownBufferIndex() const { return (_glBufferIndex != GLBUFFER_INDEX_UNKNOWN); }; - void setBufferIndex(glBufferIndex index) { _glBufferIndex = index; }; - VoxelSystem* getVoxelSystem() const { return _voxelSystem; }; - void setVoxelSystem(VoxelSystem* voxelSystem) { _voxelSystem = voxelSystem; }; + glBufferIndex getBufferIndex() const { return _glBufferIndex; } + bool isKnownBufferIndex() const { return (_glBufferIndex != GLBUFFER_INDEX_UNKNOWN); } + void setBufferIndex(glBufferIndex index) { _glBufferIndex = index; } + VoxelSystem* getVoxelSystem() const { return _voxelSystem; } + void setVoxelSystem(VoxelSystem* voxelSystem) { _voxelSystem = voxelSystem; } // Used by VoxelSystem for rendering in/out of view and LOD @@ -89,10 +89,10 @@ public: #ifndef NO_FALSE_COLOR // !NO_FALSE_COLOR means, does have false color void setFalseColor(colorPart red, colorPart green, colorPart blue); void setFalseColored(bool isFalseColored); - bool getFalseColored() { return _falseColored; }; + bool getFalseColored() { return _falseColored; } void setColor(const nodeColor& color); - const nodeColor& getTrueColor() const { return _trueColor; }; - const nodeColor& getColor() const { return _currentColor; }; + const nodeColor& getTrueColor() const { return _trueColor; } + const nodeColor& getColor() const { return _currentColor; } #else void setFalseColor(colorPart red, colorPart green, colorPart blue) { /* no op */ }; void setFalseColored(bool isFalseColored) { /* no op */ }; @@ -103,18 +103,18 @@ public: const nodeColor& getColor() const { return _trueColor; }; #endif - void setDensity(float density) { _density = density; }; - float getDensity() const { return _density; }; - void setSourceID(uint16_t sourceID) { _sourceID = sourceID; }; - uint16_t getSourceID() const { return _sourceID; }; + void setDensity(float density) { _density = density; } + float getDensity() const { return _density; } + void setSourceID(uint16_t sourceID) { _sourceID = sourceID; } + uint16_t getSourceID() const { return _sourceID; } static void addDeleteHook(VoxelNodeDeleteHook* hook); static void removeDeleteHook(VoxelNodeDeleteHook* hook); void recalculateSubTreeNodeCount(); - unsigned long getSubTreeNodeCount() const { return _subtreeNodeCount; }; - unsigned long getSubTreeInternalNodeCount() const { return _subtreeNodeCount - _subtreeLeafNodeCount; }; - unsigned long getSubTreeLeafNodeCount() const { return _subtreeLeafNodeCount; }; + unsigned long getSubTreeNodeCount() const { return _subtreeNodeCount; } + unsigned long getSubTreeInternalNodeCount() const { return _subtreeNodeCount - _subtreeLeafNodeCount; } + unsigned long getSubTreeLeafNodeCount() const { return _subtreeLeafNodeCount; } private: void calculateAABox(); diff --git a/libraries/voxels/src/VoxelNodeBag.h b/libraries/voxels/src/VoxelNodeBag.h index a29e7678c9..01d7303165 100644 --- a/libraries/voxels/src/VoxelNodeBag.h +++ b/libraries/voxels/src/VoxelNodeBag.h @@ -27,8 +27,8 @@ public: bool contains(VoxelNode* node); // is this node in the bag? void remove(VoxelNode* node); // remove a specific item from the bag - bool isEmpty() const { return (_elementsInUse == 0); }; - int count() const { return _elementsInUse; }; + bool isEmpty() const { return (_elementsInUse == 0); } + int count() const { return _elementsInUse; } void deleteAll(); diff --git a/libraries/voxels/src/VoxelProjectedPolygon.h b/libraries/voxels/src/VoxelProjectedPolygon.h index 5846b3d34d..51daf28330 100644 --- a/libraries/voxels/src/VoxelProjectedPolygon.h +++ b/libraries/voxels/src/VoxelProjectedPolygon.h @@ -19,19 +19,19 @@ class BoundingBox { public: enum { BOTTOM_LEFT, BOTTOM_RIGHT, TOP_RIGHT, TOP_LEFT, VERTEX_COUNT }; - BoundingBox(glm::vec2 corner, glm::vec2 size) : corner(corner), size(size), _set(true) {}; - BoundingBox() : _set(false) {}; + BoundingBox(glm::vec2 corner, glm::vec2 size) : corner(corner), size(size), _set(true) {} + BoundingBox() : _set(false) {} glm::vec2 corner; glm::vec2 size; bool contains(const BoundingBox& box) const; bool contains(const glm::vec2& point) const; - bool pointInside(const glm::vec2& point) const { return contains(point); }; - + bool pointInside(const glm::vec2& point) const { return contains(point); } + void explandToInclude(const BoundingBox& box); - float area() const { return size.x * size.y; }; + float area() const { return size.x * size.y; } - int getVertexCount() const { return VERTEX_COUNT; }; + int getVertexCount() const { return VERTEX_COUNT; } glm::vec2 getVertex(int vertexNumber) const; BoundingBox topHalf() const; @@ -66,23 +66,23 @@ public: _vertexCount(vertexCount), _maxX(-FLT_MAX), _maxY(-FLT_MAX), _minX(FLT_MAX), _minY(FLT_MAX), _distance(0) - { }; + { } - ~VoxelProjectedPolygon() { }; - const ProjectedVertices& getVertices() const { return _vertices; }; - const glm::vec2& getVertex(int i) const { return _vertices[i]; }; + ~VoxelProjectedPolygon() { } + const ProjectedVertices& getVertices() const { return _vertices; } + const glm::vec2& getVertex(int i) const { return _vertices[i]; } void setVertex(int vertex, const glm::vec2& point); - int getVertexCount() const { return _vertexCount; }; - void setVertexCount(int vertexCount) { _vertexCount = vertexCount; }; + int getVertexCount() const { return _vertexCount; } + void setVertexCount(int vertexCount) { _vertexCount = vertexCount; } float getDistance() const { return _distance; } void setDistance(float distance) { _distance = distance; } - bool getAnyInView() const { return _anyInView; }; - void setAnyInView(bool anyInView) { _anyInView = anyInView; }; - bool getAllInView() const { return _allInView; }; - void setAllInView(bool allInView) { _allInView = allInView; }; - void setProjectionType(unsigned char type) { _projectionType = type; }; - unsigned char getProjectionType() const { return _projectionType; }; + bool getAnyInView() const { return _anyInView; } + void setAnyInView(bool anyInView) { _anyInView = anyInView; } + bool getAllInView() const { return _allInView; } + void setAllInView(bool allInView) { _allInView = allInView; } + void setProjectionType(unsigned char type) { _projectionType = type; } + unsigned char getProjectionType() const { return _projectionType; } bool pointInside(const glm::vec2& point, bool* matchesVertex = NULL) const; diff --git a/libraries/voxels/src/VoxelSceneStats.h b/libraries/voxels/src/VoxelSceneStats.h index 0883de45e1..fe358c686c 100644 --- a/libraries/voxels/src/VoxelSceneStats.h +++ b/libraries/voxels/src/VoxelSceneStats.h @@ -120,7 +120,7 @@ public: /// Returns details about items tracked by VoxelSceneStats /// \param Item item The item from the stats you're interested in. - ItemInfo& getItemInfo(Item item) { return _ITEMS[item]; }; + ItemInfo& getItemInfo(Item item) { return _ITEMS[item]; } /// Returns a UI formatted value of an item tracked by VoxelSceneStats /// \param Item item The item from the stats you're interested in. diff --git a/libraries/voxels/src/VoxelTree.h b/libraries/voxels/src/VoxelTree.h index 4128ba6cbd..4425bb96b1 100644 --- a/libraries/voxels/src/VoxelTree.h +++ b/libraries/voxels/src/VoxelTree.h @@ -158,10 +158,10 @@ public: int encodeTreeBitstream(VoxelNode* node, unsigned char* outputBuffer, int availableBytes, VoxelNodeBag& bag, EncodeBitstreamParams& params) ; - bool isDirty() const { return _isDirty; }; - void clearDirtyBit() { _isDirty = false; }; - void setDirtyBit() { _isDirty = true; }; - unsigned long int getNodesChangedFromBitstream() const { return _nodesChangedFromBitstream; }; + bool isDirty() const { return _isDirty; } + void clearDirtyBit() { _isDirty = false; } + void setDirtyBit() { _isDirty = true; } + unsigned long int getNodesChangedFromBitstream() const { return _nodesChangedFromBitstream; } bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, VoxelNode*& node, float& distance, BoxFace& face); From a1e433e189e91614a88e3f3527613a8a8f9a55aa Mon Sep 17 00:00:00 2001 From: atlante45 Date: Wed, 4 Sep 2013 10:24:10 -0700 Subject: [PATCH 5/7] Updated Application destructor --- interface/src/Application.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 494a1e6976..5fbf6f928e 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -237,6 +237,12 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : Application::~Application() { NodeList::getInstance()->removeHook(&_voxels); NodeList::getInstance()->removeHook(this); + + delete _oculusProgram; + delete _settings; + delete _networkAccessManager; + delete _followMode; + delete _glWidget; } void Application::initializeGL() { From 1781abe9375bee5f465132f8cb957285a27b511a Mon Sep 17 00:00:00 2001 From: atlante45 Date: Wed, 4 Sep 2013 10:40:42 -0700 Subject: [PATCH 6/7] Added Menu instance deletion in Application destructor. --- interface/src/Application.cpp | 2 ++ interface/src/Menu.cpp | 1 - interface/src/Menu.h | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 5fbf6f928e..e80665b0f7 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -238,6 +238,8 @@ Application::~Application() { NodeList::getInstance()->removeHook(&_voxels); NodeList::getInstance()->removeHook(this); + delete Menu::getInstance(); + delete _oculusProgram; delete _settings; delete _networkAccessManager; diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index dc288fd73b..1fcc5a6274 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -414,7 +414,6 @@ Menu::Menu() : } Menu::~Menu() { - qDebug("[DEBUG] Menu destructor.\n]"); bandwidthDetailsClosed(); voxelStatsDetailsClosed(); delete _voxelModeActionsGroup; diff --git a/interface/src/Menu.h b/interface/src/Menu.h index e207ffe32d..676d8aefba 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -38,6 +38,7 @@ class Menu : public QMenuBar { Q_OBJECT public: static Menu* getInstance(); + ~Menu(); bool isOptionChecked(const QString& menuOption); void triggerOption(const QString& menuOption); @@ -79,7 +80,6 @@ private: static Menu* _instance; Menu(); - ~Menu(); typedef void(*settingsAction)(QSettings*, QAction*); static void loadAction(QSettings* set, QAction* action); From 5da525fc3ecb7916e373005aaa502deb9ff9f125 Mon Sep 17 00:00:00 2001 From: atlante45 Date: Wed, 4 Sep 2013 15:12:24 -0700 Subject: [PATCH 7/7] memory wastes and code cleaning PR comments --- interface/src/Audio.h | 4 +- interface/src/Menu.cpp | 1 - interface/src/VoxelSystem.cpp | 5 +- interface/src/VoxelSystem.h | 11 ++-- interface/src/avatar/AvatarVoxelSystem.cpp | 4 +- interface/src/avatar/AvatarVoxelSystem.h | 3 +- interface/src/avatar/Face.cpp | 3 - interface/src/avatar/Head.cpp | 9 +-- interface/src/avatar/Head.h | 6 +- interface/src/ui/VoxelStatsDialog.cpp | 6 +- libraries/avatars/src/AvatarData.h | 4 +- libraries/shared/src/NetworkPacket.h | 2 +- libraries/shared/src/NodeList.h | 1 - libraries/shared/src/PointerStack.cpp | 42 -------------- libraries/shared/src/PointerStack.h | 59 -------------------- libraries/shared/src/StdDev.h | 2 +- libraries/voxels/src/Tags.cpp | 10 +++- libraries/voxels/src/VoxelNode.h | 18 +++--- libraries/voxels/src/VoxelProjectedPolygon.h | 20 +++---- libraries/voxels/src/VoxelTree.cpp | 55 ------------------ libraries/voxels/src/VoxelTree.h | 7 --- 21 files changed, 47 insertions(+), 225 deletions(-) delete mode 100644 libraries/shared/src/PointerStack.cpp delete mode 100644 libraries/shared/src/PointerStack.h diff --git a/interface/src/Audio.h b/interface/src/Audio.h index c9fc8402e7..bf99fd3f42 100644 --- a/interface/src/Audio.h +++ b/interface/src/Audio.h @@ -42,8 +42,8 @@ public: float getLastInputLoudness() const { return _lastInputLoudness; } - void setLastAcceleration(glm::vec3 lastAcceleration) { _lastAcceleration = lastAcceleration; } - void setLastVelocity(glm::vec3 lastVelocity) { _lastVelocity = lastVelocity; } + void setLastAcceleration(const glm::vec3 lastAcceleration) { _lastAcceleration = lastAcceleration; } + void setLastVelocity(const glm::vec3 lastVelocity) { _lastVelocity = lastVelocity; } void setJitterBufferSamples(int samples) { _jitterBufferSamples = samples; } int getJitterBufferSamples() { return _jitterBufferSamples; } diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 1fcc5a6274..65afc605b0 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -416,7 +416,6 @@ Menu::Menu() : Menu::~Menu() { bandwidthDetailsClosed(); voxelStatsDetailsClosed(); - delete _voxelModeActionsGroup; } void Menu::loadSettings(QSettings* settings) { diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index 5229873164..d12d97a5da 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -545,7 +545,6 @@ glm::vec3 VoxelSystem::computeVoxelVertex(const glm::vec3& startVertex, float vo return startVertex + glm::vec3(identityVertex[0], identityVertex[1], identityVertex[2]) * voxelScale; } -bool VoxelSystem::_perlinModulateProgramInitialized = false; ProgramObject VoxelSystem::_perlinModulateProgram; void VoxelSystem::init() { @@ -634,7 +633,7 @@ void VoxelSystem::init() { // create our simple fragment shader if we're the first system to init - if (!_perlinModulateProgramInitialized) { + if (!_perlinModulateProgram.isLinked()) { switchToResourcesParentIfRequired(); _perlinModulateProgram.addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/perlin_modulate.vert"); _perlinModulateProgram.addShaderFromSourceFile(QGLShader::Fragment, "resources/shaders/perlin_modulate.frag"); @@ -643,8 +642,6 @@ void VoxelSystem::init() { _perlinModulateProgram.bind(); _perlinModulateProgram.setUniformValue("permutationNormalTexture", 0); _perlinModulateProgram.release(); - - _perlinModulateProgramInitialized = true; } _initialized = true; } diff --git a/interface/src/VoxelSystem.h b/interface/src/VoxelSystem.h index 35931d3191..fa4266d30a 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -34,8 +34,8 @@ public: VoxelSystem(float treeScale = TREE_SCALE, int maxVoxels = MAX_VOXELS_PER_SYSTEM); ~VoxelSystem(); - void setDataSourceID(int dataSourceID) { _dataSourceID = dataSourceID; }; - int getDataSourceID() const { return _dataSourceID; }; + void setDataSourceID(int dataSourceID) { _dataSourceID = dataSourceID; } + int getDataSourceID() const { return _dataSourceID; } int parseData(unsigned char* sourceBuffer, int numBytes); @@ -45,8 +45,8 @@ public: ViewFrustum* getViewFrustum() const {return _viewFrustum;} void setViewFrustum(ViewFrustum* viewFrustum) {_viewFrustum = viewFrustum;} - unsigned long getVoxelsUpdated() const {return _voxelsUpdated;}; - unsigned long getVoxelsRendered() const {return _voxelsInReadArrays;}; + unsigned long getVoxelsUpdated() const {return _voxelsUpdated;} + unsigned long getVoxelsRendered() const {return _voxelsInReadArrays;} void loadVoxelsFile(const char* fileName,bool wantColorRandomizer); void writeToSVOFile(const char* filename, VoxelNode* node) const; @@ -207,8 +207,7 @@ private: void updatePartialVBOs(); // multiple segments, only dirty voxels bool _voxelsDirty; - - static bool _perlinModulateProgramInitialized; + static ProgramObject _perlinModulateProgram; int _hookID; diff --git a/interface/src/avatar/AvatarVoxelSystem.cpp b/interface/src/avatar/AvatarVoxelSystem.cpp index 2b33c05807..15ece16ecd 100644 --- a/interface/src/avatar/AvatarVoxelSystem.cpp +++ b/interface/src/avatar/AvatarVoxelSystem.cpp @@ -43,7 +43,6 @@ AvatarVoxelSystem::~AvatarVoxelSystem() { } } -bool AvatarVoxelSystem::_skinProgramInitialized = false; ProgramObject AvatarVoxelSystem::_skinProgram; int AvatarVoxelSystem::_boneMatricesLocation; int AvatarVoxelSystem::_boneIndicesLocation; @@ -75,10 +74,9 @@ void AvatarVoxelSystem::init() { glBufferData(GL_ARRAY_BUFFER, BONE_ELEMENTS_PER_VOXEL * sizeof(GLfloat) * _maxVoxels, NULL, GL_DYNAMIC_DRAW); // load our skin program if this is the first avatar system to initialize - if (!_skinProgramInitialized) { + if (!_skinProgram.isLinked()) { _skinProgram.addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/skin_voxels.vert"); _skinProgram.link(); - _skinProgramInitialized = true; } _boneMatricesLocation = _skinProgram.uniformLocation("boneMatrices"); diff --git a/interface/src/avatar/AvatarVoxelSystem.h b/interface/src/avatar/AvatarVoxelSystem.h index bf95b774c3..43c76fb5c2 100644 --- a/interface/src/avatar/AvatarVoxelSystem.h +++ b/interface/src/avatar/AvatarVoxelSystem.h @@ -74,8 +74,7 @@ private: GLuint _vboBoneWeightsID; QNetworkReply* _voxelReply; - - static bool _skinProgramInitialized; + static ProgramObject _skinProgram; static int _boneMatricesLocation; static int _boneIndicesLocation; diff --git a/interface/src/avatar/Face.cpp b/interface/src/avatar/Face.cpp index cc9b90ad4a..6e8db503fa 100644 --- a/interface/src/avatar/Face.cpp +++ b/interface/src/avatar/Face.cpp @@ -54,9 +54,6 @@ Face::~Face() { glDeleteTextures(1, &_depthTextureID); } } - - glDeleteBuffers(1, &_vboID); - glDeleteBuffers(1, &_iboID); } void Face::setFrameFromWebcam() { diff --git a/interface/src/avatar/Head.cpp b/interface/src/avatar/Head.cpp index 20c4c6c816..5e04a2b1e7 100644 --- a/interface/src/avatar/Head.cpp +++ b/interface/src/avatar/Head.cpp @@ -46,7 +46,6 @@ const float IRIS_RADIUS = 0.007; const float IRIS_PROTRUSION = 0.0145f; const char IRIS_TEXTURE_FILENAME[] = "resources/images/iris.png"; -bool Head::_irisProgramInitialized = false; ProgramObject Head::_irisProgram; GLuint Head::_irisTextureID; int Head::_eyePositionLocation; @@ -97,12 +96,8 @@ Head::Head(Avatar* owningAvatar) : } } -Head::~Head() { - glDeleteTextures(1, &_irisTextureID); -} - void Head::init() { - if (!_irisProgramInitialized) { + if (!_irisProgram.isLinked()) { switchToResourcesParentIfRequired(); _irisProgram.addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/iris.vert"); _irisProgram.addShaderFromSourceFile(QGLShader::Fragment, "resources/shaders/iris.frag"); @@ -120,8 +115,6 @@ void Head::init() { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glBindTexture(GL_TEXTURE_2D, 0); - - _irisProgramInitialized = true; } } diff --git a/interface/src/avatar/Head.h b/interface/src/avatar/Head.h index 0952de0252..41886ad2f5 100644 --- a/interface/src/avatar/Head.h +++ b/interface/src/avatar/Head.h @@ -38,7 +38,6 @@ class ProgramObject; class Head : public HeadData { public: Head(Avatar* owningAvatar); - ~Head(); void init(); void reset(); @@ -73,7 +72,7 @@ public: Face& getFace() { return _face; } const bool getReturnToCenter() const { return _returnHeadToCenter; } // Do you want head to try to return to center (depends on interface detected) - float getAverageLoudness() {return _averageLoudness;} + float getAverageLoudness() const { return _averageLoudness; } glm::vec3 calculateAverageEyePosition() { return _leftEyePosition + (_rightEyePosition - _leftEyePosition ) * ONE_HALF; } float yawRate; @@ -131,8 +130,7 @@ private: bool _cameraFollowsHead; float _cameraFollowHeadRate; Face _face; - - static bool _irisProgramInitialized; + static ProgramObject _irisProgram; static GLuint _irisTextureID; static int _eyePositionLocation; diff --git a/interface/src/ui/VoxelStatsDialog.cpp b/interface/src/ui/VoxelStatsDialog.cpp index 5892c2c70e..2fa9ff8cd3 100644 --- a/interface/src/ui/VoxelStatsDialog.cpp +++ b/interface/src/ui/VoxelStatsDialog.cpp @@ -30,7 +30,7 @@ VoxelStatsDialog::VoxelStatsDialog(QWidget* parent, VoxelSceneStats* model) : this->QDialog::setLayout(form); // Setup labels - for (int i = 0; i < (int)VoxelSceneStats::ITEM_COUNT; i++) { + for (int i = 0; i < VoxelSceneStats::ITEM_COUNT; i++) { VoxelSceneStats::Item item = (VoxelSceneStats::Item)(i); VoxelSceneStats::ItemInfo& itemInfo = _model->getItemInfo(item); QLabel* label = _labels[item] = new QLabel(); @@ -54,7 +54,7 @@ VoxelStatsDialog::VoxelStatsDialog(QWidget* parent, VoxelSceneStats* model) : } VoxelStatsDialog::~VoxelStatsDialog() { - for (int i = 0; i <(int)VoxelSceneStats::ITEM_COUNT; ++i) { + for (int i = 0; i < VoxelSceneStats::ITEM_COUNT; ++i) { delete _labels[i]; } } @@ -63,7 +63,7 @@ void VoxelStatsDialog::paintEvent(QPaintEvent* event) { // Update labels char strBuf[256]; - for (int i = 0; i < (int)VoxelSceneStats::ITEM_COUNT; i++) { + for (int i = 0; i < VoxelSceneStats::ITEM_COUNT; i++) { VoxelSceneStats::Item item = (VoxelSceneStats::Item)(i); QLabel* label = _labels[item]; snprintf(strBuf, sizeof(strBuf), "%s", _model->getItemValue(item)); diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 2179cb3c4d..4f5e503cf4 100755 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -73,13 +73,13 @@ public: void setBodyYaw(float bodyYaw) { _bodyYaw = bodyYaw; } float getBodyPitch() const { return _bodyPitch; } void setBodyPitch(float bodyPitch) { _bodyPitch = bodyPitch; } - float getBodyRoll() const {return _bodyRoll; } + float getBodyRoll() const { return _bodyRoll; } void setBodyRoll(float bodyRoll) { _bodyRoll = bodyRoll; } // Hand State void setHandState(char s) { _handState = s; } - char getHandState() const {return _handState; } + char getHandState() const { return _handState; } // getters for camera details const glm::vec3& getCameraPosition() const { return _cameraPosition; } diff --git a/libraries/shared/src/NetworkPacket.h b/libraries/shared/src/NetworkPacket.h index 8017f7057e..9c7c61e10f 100644 --- a/libraries/shared/src/NetworkPacket.h +++ b/libraries/shared/src/NetworkPacket.h @@ -33,7 +33,7 @@ public: NetworkPacket(sockaddr& address, unsigned char* packetData, ssize_t packetLength); sockaddr& getAddress() { return _address; } - ssize_t getLength() const { return _packetLength; } + ssize_t getLength() const { return _packetLength; } unsigned char* getData() { return &_packetData[0]; } const sockaddr& getAddress() const { return _address; } diff --git a/libraries/shared/src/NodeList.h b/libraries/shared/src/NodeList.h index b76eab9da0..9e9f72767d 100644 --- a/libraries/shared/src/NodeList.h +++ b/libraries/shared/src/NodeList.h @@ -156,7 +156,6 @@ private: class NodeListIterator : public std::iterator { public: NodeListIterator(const NodeList* nodeList, int nodeIndex); - ~NodeListIterator() {} int getNodeIndex() { return _nodeIndex; } diff --git a/libraries/shared/src/PointerStack.cpp b/libraries/shared/src/PointerStack.cpp deleted file mode 100644 index 2098312298..0000000000 --- a/libraries/shared/src/PointerStack.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// -// PointerStack.cpp -// hifi -// -// Created by Brad Hefta-Gaub on 5/11/2013 -// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. -// - -#include "PointerStack.h" -#include - -PointerStack::~PointerStack() { - deleteAll(); -} - -void PointerStack::deleteAll() { - if (_elements) { - delete[] _elements; - } - _elements = NULL; - _elementsInUse = 0; - _sizeOfElementsArray = 0; -} - -const int GROW_BY = 100; - -void PointerStack::growAndPush(void* element) { - //printf("PointerStack::growAndPush() _sizeOfElementsArray=%d",_sizeOfElementsArray); - void** oldElements = _elements; - _elements = new void* [_sizeOfElementsArray + GROW_BY]; - _sizeOfElementsArray += GROW_BY; - - // If we had an old stack... - if (oldElements) { - // copy old elements into the new stack - memcpy(_elements, oldElements, _elementsInUse * sizeof(void*)); - delete[] oldElements; - } - _elements[_elementsInUse] = element; - _elementsInUse++; -} - diff --git a/libraries/shared/src/PointerStack.h b/libraries/shared/src/PointerStack.h deleted file mode 100644 index 1626db3a3b..0000000000 --- a/libraries/shared/src/PointerStack.h +++ /dev/null @@ -1,59 +0,0 @@ -// -// PointerStack.h -// hifi -// -// Created by Brad Hefta-Gaub on 4/25/2013 -// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. -// -// - -#ifndef __hifi__PointerStack__ -#define __hifi__PointerStack__ - -#include // for NULL - -class PointerStack { - -public: - PointerStack() : - _elements(NULL), - _elementsInUse(0), - _sizeOfElementsArray(0) {} - - ~PointerStack(); - - void push(void* element) { - if (_sizeOfElementsArray < _elementsInUse + 1) { - return growAndPush(element); - } - _elements[_elementsInUse] = element; - _elementsInUse++; - } - - void* pop() { - if (_elementsInUse) { - // get the last element - void* element = _elements[_elementsInUse - 1]; - // reduce the count - _elementsInUse--; - return element; - } - return NULL; - } - - - void* top() const { return (_elementsInUse) ? _elements[_elementsInUse - 1] : NULL; } - bool isEmpty() const { return (_elementsInUse == 0); } - bool empty() const { return (_elementsInUse == 0); } - int count() const { return _elementsInUse; } - int size() const { return _elementsInUse; } - -private: - void growAndPush(void* element); - void deleteAll(); - void** _elements; - int _elementsInUse; - int _sizeOfElementsArray; -}; - -#endif /* defined(__hifi__PointerStack__) */ diff --git a/libraries/shared/src/StdDev.h b/libraries/shared/src/StdDev.h index 74937f6f9a..eea0cff3bb 100644 --- a/libraries/shared/src/StdDev.h +++ b/libraries/shared/src/StdDev.h @@ -16,7 +16,7 @@ class StDev { void addValue(float v); float getAverage(); float getStDev(); - int getSamples() {return sampleCount;} + int getSamples() const { return sampleCount; } private: float * data; int sampleCount; diff --git a/libraries/voxels/src/Tags.cpp b/libraries/voxels/src/Tags.cpp index ef0a2a1faf..4d1fb322cd 100644 --- a/libraries/voxels/src/Tags.cpp +++ b/libraries/voxels/src/Tags.cpp @@ -109,7 +109,10 @@ TagList::TagList(std::stringstream &ss) : } TagList::~TagList() { - _data.clear(); + while (!_data.empty()) { + delete _data.back(); + _data.pop_back(); + } } TagCompound::TagCompound(std::stringstream &ss) : @@ -150,7 +153,10 @@ TagCompound::TagCompound(std::stringstream &ss) : } TagCompound::~TagCompound() { - _data.clear(); + while (!_data.empty()) { + delete _data.back(); + _data.pop_back(); + } } TagIntArray::TagIntArray(std::stringstream &ss) : Tag(TAG_Int_Array, ss) { diff --git a/libraries/voxels/src/VoxelNode.h b/libraries/voxels/src/VoxelNode.h index c98b26744c..b7f31e3b61 100644 --- a/libraries/voxels/src/VoxelNode.h +++ b/libraries/voxels/src/VoxelNode.h @@ -53,7 +53,7 @@ public: float getEnclosingRadius() const; - bool isColored() const { return (_trueColor[3]==1); } + bool isColored() const { return _trueColor[3] == 1; } bool isInView(const ViewFrustum& viewFrustum) const; ViewFrustum::location inFrustum(const ViewFrustum& viewFrustum) const; float distanceToCamera(const ViewFrustum& viewFrustum) const; @@ -70,8 +70,8 @@ public: void printDebugDetails(const char* label) const; bool isDirty() const { return _isDirty; } void clearDirtyBit() { _isDirty = false; } - bool hasChangedSince(uint64_t time) const { return (_lastChanged > time); } - void markWithChangedTime() { _lastChanged = usecTimestampNow(); } + bool hasChangedSince(uint64_t time) const { return (_lastChanged > time); } + void markWithChangedTime() { _lastChanged = usecTimestampNow(); } uint64_t getLastChanged() const { return _lastChanged; } void handleSubtreeChanged(VoxelTree* myTree); @@ -103,18 +103,18 @@ public: const nodeColor& getColor() const { return _trueColor; }; #endif - void setDensity(float density) { _density = density; } - float getDensity() const { return _density; } - void setSourceID(uint16_t sourceID) { _sourceID = sourceID; } - uint16_t getSourceID() const { return _sourceID; } + void setDensity(float density) { _density = density; } + float getDensity() const { return _density; } + void setSourceID(uint16_t sourceID) { _sourceID = sourceID; } + uint16_t getSourceID() const { return _sourceID; } static void addDeleteHook(VoxelNodeDeleteHook* hook); static void removeDeleteHook(VoxelNodeDeleteHook* hook); void recalculateSubTreeNodeCount(); - unsigned long getSubTreeNodeCount() const { return _subtreeNodeCount; } + unsigned long getSubTreeNodeCount() const { return _subtreeNodeCount; } unsigned long getSubTreeInternalNodeCount() const { return _subtreeNodeCount - _subtreeLeafNodeCount; } - unsigned long getSubTreeLeafNodeCount() const { return _subtreeLeafNodeCount; } + unsigned long getSubTreeLeafNodeCount() const { return _subtreeLeafNodeCount; } private: void calculateAABox(); diff --git a/libraries/voxels/src/VoxelProjectedPolygon.h b/libraries/voxels/src/VoxelProjectedPolygon.h index 51daf28330..1d7ac9713c 100644 --- a/libraries/voxels/src/VoxelProjectedPolygon.h +++ b/libraries/voxels/src/VoxelProjectedPolygon.h @@ -19,7 +19,7 @@ class BoundingBox { public: enum { BOTTOM_LEFT, BOTTOM_RIGHT, TOP_RIGHT, TOP_LEFT, VERTEX_COUNT }; - BoundingBox(glm::vec2 corner, glm::vec2 size) : corner(corner), size(size), _set(true) {} + BoundingBox(const glm::vec2 corner, const glm::vec2 size) : corner(corner), size(size), _set(true) {} BoundingBox() : _set(false) {} glm::vec2 corner; glm::vec2 size; @@ -73,16 +73,16 @@ public: const glm::vec2& getVertex(int i) const { return _vertices[i]; } void setVertex(int vertex, const glm::vec2& point); - int getVertexCount() const { return _vertexCount; } - void setVertexCount(int vertexCount) { _vertexCount = vertexCount; } - float getDistance() const { return _distance; } - void setDistance(float distance) { _distance = distance; } - bool getAnyInView() const { return _anyInView; } - void setAnyInView(bool anyInView) { _anyInView = anyInView; } - bool getAllInView() const { return _allInView; } - void setAllInView(bool allInView) { _allInView = allInView; } + int getVertexCount() const { return _vertexCount; } + float getDistance() const { return _distance; } + bool getAnyInView() const { return _anyInView; } + bool getAllInView() const { return _allInView; } + unsigned char getProjectionType() const { return _projectionType; } + void setVertexCount(int vertexCount) { _vertexCount = vertexCount; } + void setDistance(float distance) { _distance = distance; } + void setAnyInView(bool anyInView) { _anyInView = anyInView; } + void setAllInView(bool allInView) { _allInView = allInView; } void setProjectionType(unsigned char type) { _projectionType = type; } - unsigned char getProjectionType() const { return _projectionType; } bool pointInside(const glm::vec2& point, bool* matchesVertex = NULL) const; diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index b17200448b..d4927a293a 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -70,61 +70,6 @@ VoxelTree::~VoxelTree() { pthread_mutex_destroy(&_deletePendingSetLock); } - -void VoxelTree::recurseTreeWithOperationDistanceSortedTimed(PointerStack* stackOfNodes, long allowedTime, - RecurseVoxelTreeOperation operation, - const glm::vec3& point, void* extraData) { - - long long start = usecTimestampNow(); - - // start case, stack empty, so start with root... - if (stackOfNodes->empty()) { - stackOfNodes->push(rootNode); - } - while (!stackOfNodes->empty()) { - VoxelNode* node = (VoxelNode*)stackOfNodes->top(); - stackOfNodes->pop(); - - if (operation(node, extraData)) { - - //sortChildren... CLOSEST to FURTHEST - // determine the distance sorted order of our children - VoxelNode* sortedChildren[NUMBER_OF_CHILDREN]; - float distancesToChildren[NUMBER_OF_CHILDREN]; - int indexOfChildren[NUMBER_OF_CHILDREN]; // not really needed - int currentCount = 0; - - for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { - VoxelNode* childNode = node->getChildAtIndex(i); - if (childNode) { - // chance to optimize, doesn't need to be actual distance!! Could be distance squared - float distanceSquared = childNode->distanceSquareToPoint(point); - currentCount = insertIntoSortedArrays((void*)childNode, distanceSquared, i, - (void**)&sortedChildren, (float*)&distancesToChildren, - (int*)&indexOfChildren, currentCount, NUMBER_OF_CHILDREN); - } - } - - //iterate sorted children FURTHEST to CLOSEST - for (int i = currentCount-1; i >= 0; i--) { - VoxelNode* child = sortedChildren[i]; - stackOfNodes->push(child); - } - } - - // at this point, we can check to see if we should bail for timing reasons - // because if we bail at this point, then reenter the while, we will basically - // be back to processing the stack from same place we left off, and all can proceed normally - long long now = usecTimestampNow(); - long elapsedTime = now - start; - - if (elapsedTime > allowedTime) { - return; // caller responsible for calling us again to finish the job! - } - } -} - - // Recurses voxel tree calling the RecurseVoxelTreeOperation function for each node. // stops recursion if operation function returns false. void VoxelTree::recurseTreeWithOperation(RecurseVoxelTreeOperation operation, void* extraData) { diff --git a/libraries/voxels/src/VoxelTree.h b/libraries/voxels/src/VoxelTree.h index 4425bb96b1..24fa723300 100644 --- a/libraries/voxels/src/VoxelTree.h +++ b/libraries/voxels/src/VoxelTree.h @@ -10,7 +10,6 @@ #define __hifi__VoxelTree__ #include -#include #include #include "CoverageMap.h" @@ -189,12 +188,6 @@ public: void recurseNodeWithOperation(VoxelNode* node, RecurseVoxelTreeOperation operation, void* extraData); void recurseNodeWithOperationDistanceSorted(VoxelNode* node, RecurseVoxelTreeOperation operation, const glm::vec3& point, void* extraData); - - - void recurseTreeWithOperationDistanceSortedTimed(PointerStack* stackOfNodes, long allowedTime, - RecurseVoxelTreeOperation operation, - const glm::vec3& point, void* extraData); - signals: void importSize(float x, float y, float z); void importProgress(int progress);