Engine: introduced deleteHelper() function

The new deleteHelper() template function takes a pointer, saves it
to a temporary, sets the passed pointer to NULL and then deletes the
object it was referring to before. This way we can spot bugs caused by
undesired references to global objects at shutdown more easily.
This commit is contained in:
Tobias Doerffel
2010-05-21 13:24:37 +02:00
parent a9abdc3e75
commit fe7d5e3d5a
3 changed files with 35 additions and 35 deletions

View File

@@ -1,7 +1,7 @@
/*
* engine.h - engine-system of LMMS
*
* Copyright (c) 2006-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2006-2010 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
@@ -207,6 +207,16 @@ public:
}
private:
// small helper function which sets the pointer to NULL before actually deleting
// the object it refers to
template<class T>
static inline void deleteHelper( T * * ptr )
{
T * tmp = *ptr;
*ptr = NULL;
delete tmp;
}
static bool s_hasGUI;
static bool s_suppressMessages;
static float s_framesPerTick;

View File

@@ -1,7 +1,7 @@
/*
* engine.cpp - implementation of LMMS' engine-system
*
* Copyright (c) 2006-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2006-2010 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
@@ -153,45 +153,32 @@ void engine::destroy()
s_mixer->stopProcessing();
delete s_projectNotes;
s_projectNotes = NULL;
delete s_songEditor;
s_songEditor = NULL;
delete s_bbEditor;
s_bbEditor = NULL;
delete s_pianoRoll;
s_pianoRoll = NULL;
delete s_automationEditor;
s_automationEditor = NULL;
delete s_fxMixerView;
s_fxMixerView = NULL;
deleteHelper( &s_projectNotes );
deleteHelper( &s_songEditor );
deleteHelper( &s_bbEditor );
deleteHelper( &s_pianoRoll );
deleteHelper( &s_automationEditor );
deleteHelper( &s_fxMixerView );
InstrumentTrackView::cleanupWindowPool();
s_song->clearProject();
delete s_bbTrackContainer;
s_bbTrackContainer = NULL;
delete s_dummyTC;
s_dummyTC = NULL;
delete s_mixer;
s_mixer = NULL;
delete s_fxMixer;
s_fxMixer = NULL;
deleteHelper( &s_bbTrackContainer );
deleteHelper( &s_dummyTC );
delete s_ladspaManager;
deleteHelper( &s_mixer );
deleteHelper( &s_fxMixer );
deleteHelper( &s_ladspaManager );
//delete configManager::inst();
delete s_projectJournal;
s_projectJournal = NULL;
deleteHelper( &s_projectJournal );
s_mainWindow = NULL;
delete s_song;
s_song = NULL;
delete s_automationRecorder;
s_automationRecorder = NULL;
deleteHelper( &s_song );
deleteHelper( &s_automationRecorder );
delete s_mergedResourceDB->provider();
s_mergedResourceDB = NULL;

View File

@@ -2,8 +2,8 @@
* track.cpp - implementation of classes concerning tracks -> necessary for
* all track-like objects (beat/bassline, sample-track...)
*
* Copyright (c) 2004-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* Copyright (c) 2004-2010 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* This program is free software; you can redistribute it and/or
@@ -1764,8 +1764,11 @@ void track::removeTCO( trackContentObject * _tco )
{
m_trackContentObjects.erase( it );
emit trackContentObjectRemoved( _tco );
engine::getSong()->updateLength();
engine::getSong()->setModified();
if( engine::getSong() )
{
engine::getSong()->updateLength();
engine::getSong()->setModified();
}
}
}