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 12:45:07 -05:00
committed by teejusb
parent bb9639ead9
commit ca1a7a0dc4
+26 -18
View File
@@ -435,12 +435,16 @@ void SongManager::LoadSongDir( RString sDir, LoadingWindow *ld, bool onlyAdditio
SongPointerVector& index_entry = m_mapSongGroupIndex[sGroupDirName];
RString group_base_name= Basename(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
if (m_mapNameToGroup.find(sGroupDirName) == m_mapNameToGroup.end())
{
m_mapNameToGroup[sGroupDirName] = group;
}
} else {
groupAlreadyLoaded = true;
}
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() );
// Don't add the group name if we didn't load any songs in this group.
if(!loaded) {
// Remove the group from the group mapping
auto it = m_mapNameToGroup.find(sGroupDirName);
if (it != m_mapNameToGroup.end())
{
m_mapNameToGroup.erase(it);
// 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.
if(!loaded) {
// Remove the group from the group mapping
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)
LoadGroupSymLinks(sDir, sGroupDirName);
}
@@ -593,7 +601,7 @@ void SongManager::FreeSongs()
{
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)
{
Group* group = it->second;