From 0270cda54dd72a35a703a252a39fc5acce59952d Mon Sep 17 00:00:00 2001 From: Crash Cringle <30600688+CrashCringle12@users.noreply.github.com> Date: Sat, 22 Mar 2025 11:49:08 -0400 Subject: [PATCH] Add additional NULL checks just in case --- src/Profile.cpp | 7 ++++--- src/Song.cpp | 1 + src/SongManager.cpp | 21 +++++++++++++++------ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/Profile.cpp b/src/Profile.cpp index add87762b0..797410755d 100644 --- a/src/Profile.cpp +++ b/src/Profile.cpp @@ -97,10 +97,11 @@ void Profile::ClearSongs() delete curr_song; } m_songs.clear(); - + LOG->Trace("Profile::ClearSongs()"); if (m_group != nullptr) { - delete m_group; + RageUtil::SafeDelete( m_group); + } } @@ -1235,7 +1236,7 @@ void Profile::LoadSongsFromDir(RString const& dir, ProfileSlot prof_slot, bool i float load_time= song_load_start_time.Ago(); LOG->Trace("Successfully loaded %zu songs in %.6f from profile.", m_songs.size(), load_time); - if (m_songs.size() <= 0) { + if (m_songs.empty()) { delete m_group; m_group = nullptr; } diff --git a/src/Song.cpp b/src/Song.cpp index 8c61ff1756..d92d2f0f12 100644 --- a/src/Song.cpp +++ b/src/Song.cpp @@ -310,6 +310,7 @@ bool Song::LoadFromSongDir(RString sDir, bool load_autosave, ProfileSlot from_pr } else { + LOG->Trace("Loading song from profile2."); m_LoadedFromProfile= from_profile; m_sGroupName= sDir.substr(1, sDir.find('/', 1) - 1); use_cache= false; diff --git a/src/SongManager.cpp b/src/SongManager.cpp index 0bcee3d7b4..06120243d0 100644 --- a/src/SongManager.cpp +++ b/src/SongManager.cpp @@ -707,9 +707,12 @@ RageColor SongManager::GetSongGroupColor( const RString &sSongGroup ) const Profile* prof= PROFILEMAN->GetProfile(pn); if(prof != nullptr) { - if(prof->m_group->GetGroupName() == sSongGroup) + if(prof->m_group != nullptr) { - return profile_song_group_colors.GetValue(pn % num_profile_song_group_colors); + if(prof->m_group->GetGroupName() == sSongGroup) + { + return profile_song_group_colors.GetValue(pn % num_profile_song_group_colors); + } } } } @@ -881,9 +884,12 @@ const std::vector &SongManager::GetSongs( const RString &sGroupName ) con Profile* prof= PROFILEMAN->GetProfile(pn); if(prof != nullptr) { - if(prof->m_group->GetGroupName() == sGroupName) + if(prof->m_group != nullptr) { - return prof->m_songs; + if(prof->m_group->GetGroupName() == sGroupName) + { + return prof->m_songs; + } } } } @@ -944,9 +950,12 @@ Group* SongManager::GetGroupFromName( const RString& sGroupName ) const Profile* prof= PROFILEMAN->GetProfile(pn); if(prof != nullptr) { - if(prof->m_group->GetGroupName() == sGroupName) + if(prof->m_group != nullptr) { - return prof->m_group; + if(prof->m_group->GetGroupName() == sGroupName) + { + return prof->m_group; + } } } }