Fixed a lot of memory leaks caused by static globals never getting

deleted and some other objects not getting deleted properly due to missing
destructors.
This commit is contained in:
Shenjoku
2013-04-18 21:17:57 -07:00
parent 5f7001ef0a
commit 01456ed0b9
29 changed files with 239 additions and 171 deletions
+43 -16
View File
@@ -268,28 +268,55 @@ bool TimingData::IsFakeAtRow( int iNoteRow ) const
*
* Note that types whose SegmentEffectAreas are "Indefinite" are NULL here,
* because they should never need to be used; we always have at least one such
* segment in the TimingData, and if not, we'll crash anyway. -- vyhd */
static const TimingSegment* DummySegments[NUM_TimingSegmentType] =
* segment in the TimingData, and if not, we'll crash anyway. -- vyhd
*
* I've modified the dummy segments a bit to use a static function trick to make
* sure the objects gets destructed instead of leaking a bunch of pointers.
*/
TimingSegment * GetDummyTimingSegment( TimingSegmentType tst )
{
NULL, // BPMSegment
smnew StopSegment,
smnew DelaySegment,
NULL, // TimeSignatureSegment
smnew WarpSegment,
NULL, // LabelSegment
NULL, // TickcountSegment
NULL, // ComboSegment
NULL, // SpeedSegment
NULL, // ScrollSegment
smnew FakeSegment
};
TimingSegment * result = NULL;
switch( tst )
{
case SEGMENT_STOP:
{
static StopSegment stopSegment;
result = &stopSegment;
break;
}
case SEGMENT_DELAY:
{
static DelaySegment delaySegment;
result = &delaySegment;
break;
}
case SEGMENT_WARP:
{
static WarpSegment warpSegment;
result = &warpSegment;
break;
}
case SEGMENT_FAKE:
{
static FakeSegment fakeSegment;
result = &fakeSegment;
break;
}
}
return result;
}
const TimingSegment* TimingData::GetSegmentAtRow( int iNoteRow, TimingSegmentType tst ) const
{
const vector<TimingSegment*> &vSegments = GetTimingSegments(tst);
if( vSegments.empty() )
return DummySegments[tst];
return GetDummyTimingSegment(tst);
int index = GetSegmentIndexAtRow( tst, iNoteRow );
const TimingSegment *seg = vSegments[index];
@@ -308,7 +335,7 @@ const TimingSegment* TimingData::GetSegmentAtRow( int iNoteRow, TimingSegmentTyp
if( seg->GetRow() == iNoteRow )
return seg;
else
return DummySegments[tst];
return GetDummyTimingSegment(tst);
}
}