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
+24 -16
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,24 +489,28 @@ 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() );
// Don't add the group name if we didn't load any songs in this group. // If we're only loading additions, already loaded groups should neither be added nor deleted
if(!loaded) { if (!(groupAlreadyLoaded && onlyAdditions)) {
// Remove the group from the group mapping
auto it = m_mapNameToGroup.find(sGroupDirName); // Don't add the group name if we didn't load any songs in this group.
if (it != m_mapNameToGroup.end()) if(!loaded) {
{ // Remove the group from the group mapping
m_mapNameToGroup.erase(it); auto it = m_mapNameToGroup.find(sGroupDirName);
if (it != m_mapNameToGroup.end())
{
m_mapNameToGroup.erase(it);
}
delete group;
continue;
} }
delete group;
continue; // Add this group to the group array.
AddGroup(sDir, sGroupDirName, group);
// Cache and load the group banner. (and background if it has one -aj)
IMAGECACHE->CacheImage( "Banner", GetSongGroupBannerPath(sGroupDirName) );
} }
// Add this group to the group array.
AddGroup(sDir, sGroupDirName, group);
// Cache and load the group banner. (and background if it has one -aj)
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;