Merge pull request #3761 from birarda/plugs

fix a memory leak in OctreeElement, StDev
This commit is contained in:
samcake 2014-11-07 17:36:14 -08:00
commit 3dec5722a0
10 changed files with 45 additions and 18 deletions

View file

@ -48,7 +48,7 @@
#include <OctreeConstants.h> #include <OctreeConstants.h>
#include <PacketHeaders.h> #include <PacketHeaders.h>
#include <SharedUtil.h> #include <SharedUtil.h>
#include <StdDev.h> #include <StDev.h>
#include <UUID.h> #include <UUID.h>
#include "AudioRingBuffer.h" #include "AudioRingBuffer.h"

View file

@ -35,7 +35,7 @@
#include <NodeList.h> #include <NodeList.h>
#include <PacketHeaders.h> #include <PacketHeaders.h>
#include <SharedUtil.h> #include <SharedUtil.h>
#include <StdDev.h> #include <StDev.h>
#include <UUID.h> #include <UUID.h>
#include <glm/glm.hpp> #include <glm/glm.hpp>

View file

@ -40,12 +40,12 @@
#include <QByteArray> #include <QByteArray>
#include <AbstractAudioInterface.h> #include <AbstractAudioInterface.h>
#include <StdDev.h> #include <StDev.h>
#include "MixedProcessedAudioStream.h" #include "MixedProcessedAudioStream.h"
#include "AudioEffectOptions.h" #include "AudioEffectOptions.h"
#include <AudioRingBuffer.h> #include <AudioRingBuffer.h>
#include <StdDev.h> #include <StDev.h>
extern "C" { extern "C" {
#include <gverb.h> #include <gverb.h>

View file

@ -90,6 +90,17 @@ Hair::Hair(int strands,
} }
} }
Hair::~Hair() {
delete[] _hairPosition;
delete[] _hairOriginalPosition;
delete[] _hairLastPosition;
delete[] _hairQuadDelta;
delete[] _hairNormals;
delete[] _hairColors;
delete[] _hairIsMoveable;
delete[] _hairConstraints;
}
const float SOUND_THRESHOLD = 40.0f; const float SOUND_THRESHOLD = 40.0f;
void Hair::simulate(float deltaTime) { void Hair::simulate(float deltaTime) {

View file

@ -37,6 +37,7 @@ public:
float radius = DEFAULT_HAIR_RADIUS, float radius = DEFAULT_HAIR_RADIUS,
float linkLength = DEFAULT_HAIR_LINK_LENGTH, float linkLength = DEFAULT_HAIR_LINK_LENGTH,
float hairThickness = DEFAULT_HAIR_THICKNESS); float hairThickness = DEFAULT_HAIR_THICKNESS);
~Hair();
void simulate(float deltaTime); void simulate(float deltaTime);
void render(); void render();
void setAcceleration(const glm::vec3& acceleration) { _acceleration = acceleration; } void setAcceleration(const glm::vec3& acceleration) { _acceleration = acceleration; }

View file

@ -18,7 +18,7 @@
#include "SequenceNumberStats.h" #include "SequenceNumberStats.h"
#include "AudioStreamStats.h" #include "AudioStreamStats.h"
#include "PacketHeaders.h" #include "PacketHeaders.h"
#include "StdDev.h" #include "StDev.h"
#include "TimeWeightedAvg.h" #include "TimeWeightedAvg.h"
// This adds some number of frames to the desired jitter buffer frames target we use when we're dropping frames. // This adds some number of frames to the desired jitter buffer frames target we use when we're dropping frames.

View file

@ -69,6 +69,7 @@ void OctreeElement::init(unsigned char * octalCode) {
_childBitmask = 0; _childBitmask = 0;
_childrenExternal = false; _childrenExternal = false;
#ifdef BLENDED_UNION_CHILDREN #ifdef BLENDED_UNION_CHILDREN
_children.external = NULL; _children.external = NULL;
_singleChildrenCount++; _singleChildrenCount++;
@ -661,6 +662,11 @@ void OctreeElement::deleteAllChildren() {
} }
} }
if (_childrenExternal) {
// if the children_t union represents _children.external we need to delete it here
delete[] _children.external;
}
#ifdef BLENDED_UNION_CHILDREN #ifdef BLENDED_UNION_CHILDREN
// now, reset our internal state and ANY and all population data // now, reset our internal state and ANY and all population data
int childCount = getChildCount(); int childCount = getChildCount();
@ -758,13 +764,18 @@ void OctreeElement::setChildAtIndex(int childIndex, OctreeElement* child) {
_children.external[firstIndex] = previousChild; _children.external[firstIndex] = previousChild;
_children.external[childIndex] = child; _children.external[childIndex] = child;
_childrenExternal = true;
_externalChildrenMemoryUsage += NUMBER_OF_CHILDREN * sizeof(OctreeElement*); _externalChildrenMemoryUsage += NUMBER_OF_CHILDREN * sizeof(OctreeElement*);
} else if (previousChildCount == 2 && newChildCount == 1) { } else if (previousChildCount == 2 && newChildCount == 1) {
assert(!child); // we are removing a child, so this must be true! assert(!child); // we are removing a child, so this must be true!
OctreeElement* previousFirstChild = _children.external[firstIndex]; OctreeElement* previousFirstChild = _children.external[firstIndex];
OctreeElement* previousSecondChild = _children.external[secondIndex]; OctreeElement* previousSecondChild = _children.external[secondIndex];
delete[] _children.external; delete[] _children.external;
_childrenExternal = false;
_externalChildrenMemoryUsage -= NUMBER_OF_CHILDREN * sizeof(OctreeElement*); _externalChildrenMemoryUsage -= NUMBER_OF_CHILDREN * sizeof(OctreeElement*);
if (childIndex == firstIndex) { if (childIndex == firstIndex) {
_children.single = previousSecondChild; _children.single = previousSecondChild;

View file

@ -1,5 +1,5 @@
// //
// StdDev.cpp // StDev.cpp
// libraries/shared/src // libraries/shared/src
// //
// Created by Philip Rosedale on 3/12/13. // Created by Philip Rosedale on 3/12/13.
@ -11,16 +11,18 @@
#include <limits> #include <limits>
#include <cmath> #include <cmath>
#include "StdDev.h" #include <cstring>
const int NUM_SAMPLES = 1000; #include "StDev.h"
StDev::StDev() { StDev::StDev() :
_data = new float[NUM_SAMPLES]; _sampleCount(0)
_sampleCount = 0; {
reset();
} }
void StDev::reset() { void StDev::reset() {
memset(&_data, 0, sizeof(_data));
_sampleCount = 0; _sampleCount = 0;
} }

View file

@ -1,5 +1,5 @@
// //
// StdDev.h // StDev.h
// libraries/shared/src // libraries/shared/src
// //
// Created by Philip Rosedale on 3/12/13. // Created by Philip Rosedale on 3/12/13.
@ -9,8 +9,10 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#ifndef hifi_StdDev_h #ifndef hifi_StDev_h
#define hifi_StdDev_h #define hifi_StDev_h
const int NUM_SAMPLES = 1000;
class StDev { class StDev {
public: public:
@ -21,8 +23,8 @@ public:
float getStDev() const; float getStDev() const;
int getSamples() const { return _sampleCount; } int getSamples() const { return _sampleCount; }
private: private:
float* _data; float _data[NUM_SAMPLES];
int _sampleCount; int _sampleCount;
}; };
#endif // hifi_StdDev_h #endif // hifi_StDev_h

View file

@ -20,7 +20,7 @@
#include <SequenceNumberStats.h> #include <SequenceNumberStats.h>
#include <SharedUtil.h> // for usecTimestampNow #include <SharedUtil.h> // for usecTimestampNow
#include <SimpleMovingAverage.h> #include <SimpleMovingAverage.h>
#include <StdDev.h> #include <StDev.h>
const quint64 MSEC_TO_USEC = 1000; const quint64 MSEC_TO_USEC = 1000;
const quint64 LARGE_STATS_TIME = 500; // we don't expect stats calculation to take more than this many usecs const quint64 LARGE_STATS_TIME = 500; // we don't expect stats calculation to take more than this many usecs