Some more memory leaks and codes formatting

This commit is contained in:
atlante45 2013-09-03 17:16:06 -07:00
parent 06119990e8
commit b03482ead5
23 changed files with 145 additions and 91 deletions

View file

@ -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();

View file

@ -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() {

View file

@ -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;

View file

@ -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() {

View file

@ -79,6 +79,7 @@ private:
static Menu* _instance;
Menu();
~Menu();
typedef void(*settingsAction)(QSettings*, QAction*);
static void loadAction(QSettings* set, QAction* action);

View file

@ -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) {

View file

@ -25,6 +25,7 @@ class Transmitter
{
public:
Transmitter();
~Transmitter();
void render();
void checkForLostTransmitter();
void resetLevels();

View file

@ -70,6 +70,10 @@ namespace starfield {
_renderer(0l) {
}
~Controller() {
delete _renderer;
}
#if !STARFIELD_MULTITHREADING
#define lock
#define _(x)

View file

@ -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; }

View file

@ -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);

View file

@ -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); }

View file

@ -156,9 +156,9 @@ private:
class NodeListIterator : public std::iterator<std::input_iterator_tag, Node> {
public:
NodeListIterator(const NodeList* nodeList, int nodeIndex);
~NodeListIterator() {};
~NodeListIterator() {}
int getNodeIndex() { return _nodeIndex; };
int getNodeIndex() { return _nodeIndex; }
NodeListIterator& operator=(const NodeListIterator& otherValue);

View file

@ -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();
};

View file

@ -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);

View file

@ -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__) */

View file

@ -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;

View file

@ -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();

View file

@ -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<Tag*> getData () const {return _data; }

View file

@ -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();

View file

@ -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();

View file

@ -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;

View file

@ -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.

View file

@ -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);