Prevent a crash when loading a group with no additions in SongManager::LoadSongDir

When reloading and only loading additions, ensure we do not delete/readd groups that were already loaded.
This commit is contained in:
Crash Cringle
2025-03-07 16:51:26 -08:00
committed by teejusb
parent bb9639ead9
commit ca1a7a0dc4
+9 -1
View File
@@ -436,10 +436,14 @@ void SongManager::LoadSongDir( RString sDir, LoadingWindow *ld, bool onlyAdditio
RString group_base_name= Basename(sGroupDirName); RString group_base_name= Basename(sGroupDirName);
Group* group = new Group(sDir, sGroupDirName); Group* group = new Group(sDir, sGroupDirName);
// We need to keep track of previously loaded groups so we don't delete them if we're only loading additions
bool groupAlreadyLoaded = false;
// Add the group to the group mapping // Add the group to the group mapping
if (m_mapNameToGroup.find(sGroupDirName) == m_mapNameToGroup.end()) if (m_mapNameToGroup.find(sGroupDirName) == m_mapNameToGroup.end())
{ {
m_mapNameToGroup[sGroupDirName] = group; m_mapNameToGroup[sGroupDirName] = group;
} else {
groupAlreadyLoaded = true;
} }
for( unsigned j=0; j< arraySongDirs.size(); ++j ) // for each song dir for( unsigned j=0; j< arraySongDirs.size(); ++j ) // for each song dir
@@ -485,6 +489,9 @@ void SongManager::LoadSongDir( RString sDir, LoadingWindow *ld, bool onlyAdditio
LOG->Trace("Loaded %i songs from \"%s\"", loaded, (sDir+sGroupDirName).c_str() ); LOG->Trace("Loaded %i songs from \"%s\"", loaded, (sDir+sGroupDirName).c_str() );
// If we're only loading additions, already loaded groups should neither be added nor deleted
if (!(groupAlreadyLoaded && onlyAdditions)) {
// Don't add the group name if we didn't load any songs in this group. // Don't add the group name if we didn't load any songs in this group.
if(!loaded) { if(!loaded) {
// Remove the group from the group mapping // Remove the group from the group mapping
@@ -502,6 +509,7 @@ void SongManager::LoadSongDir( RString sDir, LoadingWindow *ld, bool onlyAdditio
// Cache and load the group banner. (and background if it has one -aj) // Cache and load the group banner. (and background if it has one -aj)
IMAGECACHE->CacheImage( "Banner", GetSongGroupBannerPath(sGroupDirName) ); IMAGECACHE->CacheImage( "Banner", GetSongGroupBannerPath(sGroupDirName) );
}
// Load the group sym links (if any) // Load the group sym links (if any)
LoadGroupSymLinks(sDir, sGroupDirName); LoadGroupSymLinks(sDir, sGroupDirName);
@@ -593,7 +601,7 @@ void SongManager::FreeSongs()
{ {
RageUtil::SafeDelete( song ); RageUtil::SafeDelete( song );
} }
// Loop through all groups in the mapand delete them. // Loop through all groups in the map and delete them.
for (auto it = m_mapNameToGroup.begin(); it != m_mapNameToGroup.end(); ++it) for (auto it = m_mapNameToGroup.begin(); it != m_mapNameToGroup.end(); ++it)
{ {
Group* group = it->second; Group* group = it->second;