Safe delete Groups
This commit is contained in:
@@ -29,6 +29,10 @@ Group::Group() {
|
|||||||
m_sAuthorsNotes = "";
|
m_sAuthorsNotes = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Group::~Group() {
|
||||||
|
SONGMAN->GetGroupGroupMap().clear();
|
||||||
|
m_sCredits.clear();
|
||||||
|
}
|
||||||
Group::Group(const RString &sPath) {
|
Group::Group(const RString &sPath) {
|
||||||
RString sGroupIniPath = sPath + "/Group.ini";
|
RString sGroupIniPath = sPath + "/Group.ini";
|
||||||
RString credits = "";
|
RString credits = "";
|
||||||
|
|||||||
+21
-13
@@ -269,7 +269,7 @@ void SongManager::SanityCheckGroupDir( RString sDir ) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SongManager::AddGroup( RString sDir, RString sGroupDirName, Group group )
|
void SongManager::AddGroup( RString sDir, RString sGroupDirName, Group* group )
|
||||||
{
|
{
|
||||||
unsigned j;
|
unsigned j;
|
||||||
for(j = 0; j < m_sSongGroupNames.size(); ++j)
|
for(j = 0; j < m_sSongGroupNames.size(); ++j)
|
||||||
@@ -285,9 +285,9 @@ void SongManager::AddGroup( RString sDir, RString sGroupDirName, Group group )
|
|||||||
std::vector<RString> arrayGroupBanners;
|
std::vector<RString> arrayGroupBanners;
|
||||||
|
|
||||||
// First check if there is a banner provided in group.ini
|
// First check if there is a banner provided in group.ini
|
||||||
if( group.GetBannerPath() != "" )
|
if( group->GetBannerPath() != "" )
|
||||||
{
|
{
|
||||||
GetDirListing( sDir+sGroupDirName+"/"+group.GetBannerPath(), arrayGroupBanners );
|
GetDirListing( sDir+sGroupDirName+"/"+group->GetBannerPath(), arrayGroupBanners );
|
||||||
}
|
}
|
||||||
GetDirListing( sDir+sGroupDirName+"/*.png", arrayGroupBanners );
|
GetDirListing( sDir+sGroupDirName+"/*.png", arrayGroupBanners );
|
||||||
GetDirListing( sDir+sGroupDirName+"/*.jpg", arrayGroupBanners );
|
GetDirListing( sDir+sGroupDirName+"/*.jpg", arrayGroupBanners );
|
||||||
@@ -339,6 +339,8 @@ void SongManager::AddGroup( RString sDir, RString sGroupDirName, Group group )
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
m_sSongGroupNames.push_back( sGroupDirName );
|
m_sSongGroupNames.push_back( sGroupDirName );
|
||||||
|
// add to the group list
|
||||||
|
m_pGroups.push_back( group );
|
||||||
|
|
||||||
if (m_mapGroupsByName.find(sGroupDirName) == m_mapGroupsByName.end())
|
if (m_mapGroupsByName.find(sGroupDirName) == m_mapGroupsByName.end())
|
||||||
{
|
{
|
||||||
@@ -346,11 +348,11 @@ void SongManager::AddGroup( RString sDir, RString sGroupDirName, Group group )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add the group to its series if the group has one and if the series exists
|
// Add the group to its series if the group has one and if the series exists
|
||||||
if( group.GetSeries() != "" )
|
if( group->GetSeries() != "" )
|
||||||
{
|
{
|
||||||
std::vector<Group*>& series = m_mapSeries[group.GetSeries()];
|
std::vector<Group*>& series = m_mapSeries[group->GetSeries()];
|
||||||
if( std::find(series.begin(), series.end(), &group) == series.end() )
|
if( std::find(series.begin(), series.end(), group) == series.end() )
|
||||||
series.push_back(&group);
|
series.push_back(group);
|
||||||
}
|
}
|
||||||
//m_sSongGroupBackgroundPaths.push_back( sBackgroundPath );
|
//m_sSongGroupBackgroundPaths.push_back( sBackgroundPath );
|
||||||
}
|
}
|
||||||
@@ -433,7 +435,7 @@ void SongManager::LoadSongDir( RString sDir, LoadingWindow *ld, bool onlyAdditio
|
|||||||
|
|
||||||
SongPointerVector& index_entry = m_mapSongGroupIndex[sGroupDirName];
|
SongPointerVector& index_entry = m_mapSongGroupIndex[sGroupDirName];
|
||||||
RString group_base_name= Basename(sGroupDirName);
|
RString group_base_name= Basename(sGroupDirName);
|
||||||
Group group = Group(sDir + sGroupDirName);
|
Group* group = new Group(sDir + sGroupDirName);
|
||||||
|
|
||||||
for( unsigned j=0; j< arraySongDirs.size(); ++j ) // for each song dir
|
for( unsigned j=0; j< arraySongDirs.size(); ++j ) // for each song dir
|
||||||
{
|
{
|
||||||
@@ -469,10 +471,10 @@ void SongManager::LoadSongDir( RString sDir, LoadingWindow *ld, bool onlyAdditio
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Apply Group Offset if applicable
|
// Apply Group Offset if applicable
|
||||||
if( group.GetSyncOffset() != 0 )
|
if( group->GetSyncOffset() != 0 )
|
||||||
{
|
{
|
||||||
LOG->Trace("Applying group offset of %i ms to \"%s\"", group.GetSyncOffset(), pNewSong->GetSongDir().c_str() );
|
LOG->Trace("Applying group offset of %i ms to \"%s\"", group->GetSyncOffset(), pNewSong->GetSongDir().c_str() );
|
||||||
pNewSong->m_SongTiming.m_fBeat0GroupOffsetInSeconds = group.GetSyncOffset();
|
pNewSong->m_SongTiming.m_fBeat0GroupOffsetInSeconds = group->GetSyncOffset();
|
||||||
const std::vector<Steps*>& vpSteps = pNewSong->GetAllSteps();
|
const std::vector<Steps*>& vpSteps = pNewSong->GetAllSteps();
|
||||||
for (Steps* s : vpSteps)
|
for (Steps* s : vpSteps)
|
||||||
{
|
{
|
||||||
@@ -480,7 +482,7 @@ void SongManager::LoadSongDir( RString sDir, LoadingWindow *ld, bool onlyAdditio
|
|||||||
// from the song and is already changed.
|
// from the song and is already changed.
|
||||||
if( s->m_Timing.empty() )
|
if( s->m_Timing.empty() )
|
||||||
continue;
|
continue;
|
||||||
s->m_Timing.m_fBeat0GroupOffsetInSeconds = group.GetSyncOffset();
|
s->m_Timing.m_fBeat0GroupOffsetInSeconds = group->GetSyncOffset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -594,7 +596,13 @@ void SongManager::FreeSongs()
|
|||||||
{
|
{
|
||||||
RageUtil::SafeDelete( song );
|
RageUtil::SafeDelete( song );
|
||||||
}
|
}
|
||||||
|
// Loop through all groups and delete them.
|
||||||
|
for (Group *group : m_pGroups) {
|
||||||
|
RageUtil::SafeDelete(group);
|
||||||
|
}
|
||||||
|
|
||||||
m_pSongs.clear();
|
m_pSongs.clear();
|
||||||
|
m_pGroups.clear();
|
||||||
m_SongsByDir.clear();
|
m_SongsByDir.clear();
|
||||||
|
|
||||||
// also free the songs that have been deleted from disk
|
// also free the songs that have been deleted from disk
|
||||||
@@ -899,7 +907,7 @@ Group* SongManager::GetGroupFromName( const RString& sGroupName ) const
|
|||||||
{
|
{
|
||||||
auto iter = m_mapGroupsByName.find( sGroupName );
|
auto iter = m_mapGroupsByName.find( sGroupName );
|
||||||
if( iter != m_mapGroupsByName.end() )
|
if( iter != m_mapGroupsByName.end() )
|
||||||
return const_cast<Group*>(&iter->second);
|
return iter->second;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-3
@@ -146,7 +146,7 @@ public:
|
|||||||
void GetPreferredSortSongs( std::vector<Song*> &AddTo ) const;
|
void GetPreferredSortSongs( std::vector<Song*> &AddTo ) const;
|
||||||
std::map<RString, std::vector<Song*>> GetPreferredSortSongsMap() const { return m_mapPreferredSectionToSongs;};
|
std::map<RString, std::vector<Song*>> GetPreferredSortSongsMap() const { return m_mapPreferredSectionToSongs;};
|
||||||
RString SongToPreferredSortSectionName( const Song *pSong ) const;
|
RString SongToPreferredSortSectionName( const Song *pSong ) const;
|
||||||
std::map<RString, Group> GetGroupGroupMap() const { return m_mapGroupsByName;};
|
std::map<RString, Group*> GetGroupGroupMap() const { return m_mapGroupsByName;};
|
||||||
std::map<RString, std::vector<Group*>> GetSeriesGroupMap() const { return m_mapSeries;};
|
std::map<RString, std::vector<Group*>> GetSeriesGroupMap() const { return m_mapSeries;};
|
||||||
Group* GetGroupFromName( const RString &sGroupName ) const;
|
Group* GetGroupFromName( const RString &sGroupName ) const;
|
||||||
std::vector<RString> GetPreferredSortSectionNames() const;
|
std::vector<RString> GetPreferredSortSectionNames() const;
|
||||||
@@ -215,12 +215,14 @@ protected:
|
|||||||
void LoadSongDir( RString sDir, LoadingWindow *ld, bool onlyAdditions );
|
void LoadSongDir( RString sDir, LoadingWindow *ld, bool onlyAdditions );
|
||||||
bool GetExtraStageInfoFromCourse( bool bExtra2, RString sPreferredGroup, Song*& pSongOut, Steps*& pStepsOut, StepsType stype );
|
bool GetExtraStageInfoFromCourse( bool bExtra2, RString sPreferredGroup, Song*& pSongOut, Steps*& pStepsOut, StepsType stype );
|
||||||
void SanityCheckGroupDir( RString sDir ) const;
|
void SanityCheckGroupDir( RString sDir ) const;
|
||||||
void AddGroup( RString sDir, RString sGroupDirName, Group group );
|
void AddGroup( RString sDir, RString sGroupDirName, Group* group );
|
||||||
int GetNumEditsLoadedFromProfile( ProfileSlot slot ) const;
|
int GetNumEditsLoadedFromProfile( ProfileSlot slot ) const;
|
||||||
|
|
||||||
void AddSongToList(Song* new_song);
|
void AddSongToList(Song* new_song);
|
||||||
/** @brief All of the songs that can be played. */
|
/** @brief All of the songs that can be played. */
|
||||||
std::vector<Song*> m_pSongs;
|
std::vector<Song*> m_pSongs;
|
||||||
|
/** @brief All of the groups available */
|
||||||
|
std::vector<Group*> m_pGroups;
|
||||||
std::map<RString, Song*> m_SongsByDir;
|
std::map<RString, Song*> m_SongsByDir;
|
||||||
std::set<RString> m_GroupsToNeverCache;
|
std::set<RString> m_GroupsToNeverCache;
|
||||||
|
|
||||||
@@ -246,7 +248,7 @@ protected:
|
|||||||
std::vector<RString> m_sSongGroupNames;
|
std::vector<RString> m_sSongGroupNames;
|
||||||
//vector<RString> m_sSongGroupBackgroundPaths; // each song group may have a background associated with it (very rarely)
|
//vector<RString> m_sSongGroupBackgroundPaths; // each song group may have a background associated with it (very rarely)
|
||||||
|
|
||||||
std::map<RString, Group> m_mapGroupsByName;
|
std::map<RString, Group*> m_mapGroupsByName;
|
||||||
std::map<RString, std::vector<Group*>> m_mapSeries;
|
std::map<RString, std::vector<Group*>> m_mapSeries;
|
||||||
|
|
||||||
struct Comp { bool operator()(const RString& s, const RString &t) const { return CompareRStringsAsc(s,t); } };
|
struct Comp { bool operator()(const RString& s, const RString &t) const { return CompareRStringsAsc(s,t); } };
|
||||||
|
|||||||
Reference in New Issue
Block a user