diff --git a/src/LifeMeterTime.cpp b/src/LifeMeterTime.cpp index aabc1db098..0a7cc27ae8 100644 --- a/src/LifeMeterTime.cpp +++ b/src/LifeMeterTime.cpp @@ -48,6 +48,12 @@ LifeMeterTime::LifeMeterTime() { m_fLifeTotalGainedSeconds = 0; m_fLifeTotalLostSeconds = 0; + m_pStream = NULL; +} + +LifeMeterTime::~LifeMeterTime() +{ + delete m_pStream; } void LifeMeterTime::Load( const PlayerState *pPlayerState, PlayerStageStats *pPlayerStageStats ) diff --git a/src/LifeMeterTime.h b/src/LifeMeterTime.h index d2bd54e69c..c975286739 100644 --- a/src/LifeMeterTime.h +++ b/src/LifeMeterTime.h @@ -16,6 +16,8 @@ class LifeMeterTime : public LifeMeter public: LifeMeterTime(); + virtual ~LifeMeterTime(); + virtual void Load( const PlayerState *pPlayerState, PlayerStageStats *pPlayerStageStats ); virtual void Update( float fDeltaTime ); diff --git a/src/RageSoundReader_Resample_Good.cpp b/src/RageSoundReader_Resample_Good.cpp index 0db532a7c1..1ee2d8bca2 100644 --- a/src/RageSoundReader_Resample_Good.cpp +++ b/src/RageSoundReader_Resample_Good.cpp @@ -11,6 +11,7 @@ #include "RageUtil.h" #include "RageMath.h" #include "RageThreads.h" +#include "RageUtil_AutoPtr.h" #include @@ -397,25 +398,28 @@ int PolyphaseFilter::NumInputsForOutputSamples( const State &State, int iOut, in return iIn; } /** @brief Utilities for working with the PolyphaseFilter cache. */ +typedef AutoPtrCopyOnWrite PolyphaseFilterAutoPtr; namespace PolyphaseFilterCache { /* Cache filter data, and reuse it without copying. All operations after creation * are const, so this doesn't cause thread-safety problems. */ - typedef map, PolyphaseFilter *> FilterMap; + typedef map, PolyphaseFilterAutoPtr> FilterMap; static RageMutex PolyphaseFiltersLock("PolyphaseFiltersLock"); static FilterMap g_mapPolyphaseFilters; - const PolyphaseFilter *MakePolyphaseFilter( int iUpFactor, float fCutoffFrequency ) + const PolyphaseFilterAutoPtr MakePolyphaseFilter( int iUpFactor, float fCutoffFrequency ) { + PolyphaseFilterAutoPtr result; + PolyphaseFiltersLock.Lock(); pair params( make_pair(iUpFactor, fCutoffFrequency) ); FilterMap::const_iterator it = g_mapPolyphaseFilters.find(params); if( it != g_mapPolyphaseFilters.end() ) { /* We already have a filter for this upsampling factor and cutoff; use it. */ - PolyphaseFilter *pPolyphase = it->second; + result = it->second; PolyphaseFiltersLock.Unlock(); - return pPolyphase; + return result; } int iWinSize = L*iUpFactor; float *pFIR = smnew float[iWinSize]; @@ -428,12 +432,14 @@ namespace PolyphaseFilterCache pPolyphase->Generate( pFIR ); delete [] pFIR; - g_mapPolyphaseFilters[params] = pPolyphase; + result = PolyphaseFilterAutoPtr(pPolyphase); + + g_mapPolyphaseFilters[params] = result; PolyphaseFiltersLock.Unlock(); - return pPolyphase; + return result; } - const PolyphaseFilter *FindNearestPolyphaseFilter( int iUpFactor, float fCutoffFrequency ) + const PolyphaseFilterAutoPtr FindNearestPolyphaseFilter( int iUpFactor, float fCutoffFrequency ) { /* Find a cached filter with the same iUpFactor and a nearby cutoff frequency. * Round the cutoff down, if possible; it's better to filter out too much than @@ -444,7 +450,7 @@ namespace PolyphaseFilterCache if( it != g_mapPolyphaseFilters.begin() ) --it; ASSERT( it->first.first == iUpFactor ); - PolyphaseFilter *pPolyphase = it->second; + PolyphaseFilterAutoPtr pPolyphase = it->second; PolyphaseFiltersLock.Unlock(); return pPolyphase; } @@ -467,7 +473,7 @@ public: * when filtering. This will only cause the low-pass filter to be rounded; * the conversion ratio will always be exact. */ m_iUpFactor = iUpFactor; - m_pPolyphase = NULL; + m_pPolyphase = PolyphaseFilterAutoPtr(NULL); int iFilterIncrement = max( (iMaxDownFactor - iMinDownFactor)/10, 1 ); for( int iDownFactor = iMinDownFactor; iDownFactor <= iMaxDownFactor; iDownFactor += iFilterIncrement ) @@ -532,13 +538,13 @@ private: return fCutoffFrequency; } - const PolyphaseFilter *GetFilter( int iDownFactor ) const + const PolyphaseFilterAutoPtr GetFilter( int iDownFactor ) const { float fCutoffFrequency = GetCutoffFrequency( iDownFactor ); return PolyphaseFilterCache::FindNearestPolyphaseFilter( m_iUpFactor, fCutoffFrequency ); } - const PolyphaseFilter *m_pPolyphase; + PolyphaseFilterAutoPtr m_pPolyphase; PolyphaseFilter::State *m_pState; int m_iUpFactor; int m_iDownFactor; diff --git a/src/StreamDisplay.cpp b/src/StreamDisplay.cpp index beb6585578..1dc1ee6f8a 100644 --- a/src/StreamDisplay.cpp +++ b/src/StreamDisplay.cpp @@ -21,6 +21,8 @@ StreamDisplay::StreamDisplay() m_fPassingAlpha = 0; m_fHotAlpha = 0; m_bAlwaysBounce = false; + + m_bDeleteChildren = true; } void StreamDisplay::Load( const RString & /* unreferenced: _sMetricsGroup */)