From 60dfaeb3a88b3843fdc594457cf5c95e37b063e9 Mon Sep 17 00:00:00 2001 From: Ansariel Date: Thu, 19 Jun 2025 00:48:38 +0200 Subject: [PATCH] Fix issue in sound explorer: end() interator gets invalidated after each erase --- indra/newview/NACLfloaterexploresounds.cpp | 37 ++++++++++------------ indra/newview/NACLfloaterexploresounds.h | 2 +- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/indra/newview/NACLfloaterexploresounds.cpp b/indra/newview/NACLfloaterexploresounds.cpp index aea03254c2..cfd2ba644e 100644 --- a/indra/newview/NACLfloaterexploresounds.cpp +++ b/indra/newview/NACLfloaterexploresounds.cpp @@ -106,23 +106,21 @@ void NACLFloaterExploreSounds::handleSelection() childSetEnabled("block_avatar_gesture_sounds_btn", num_selected); } -LLSoundHistoryItem NACLFloaterExploreSounds::getItem(const LLUUID& itemID) +LLSoundHistoryItem NACLFloaterExploreSounds::getItem(const LLUUID& itemID) const { - std::map::iterator found = gSoundHistory.find(itemID); - if (found != gSoundHistory.end()) + if (auto found = gSoundHistory.find(itemID); found != gSoundHistory.end()) { return found->second; } else { // If log is paused, hopefully we can find it in mLastHistory - if (auto found = std::find_if(mLastHistory.begin(), mLastHistory.end(), [&](const auto& item) { return item.mID == itemID; }); - found != mLastHistory.end()) - return *found; + if (auto foundHistory = std::find_if(mLastHistory.begin(), mLastHistory.end(), [&](const auto& item) { return item.mID == itemID; }); + foundHistory != mLastHistory.end()) + return *foundHistory; } - LLSoundHistoryItem item; - item.mID.setNull(); - return item; + + return {}; } class LLSoundHistoryItemCompare @@ -306,8 +304,7 @@ bool NACLFloaterExploreSounds::tick() // Clean up stopped local audio source IDs uuid_vec_t::iterator audio_src_id_iter = mLocalPlayingAudioSourceIDs.begin(); - uuid_vec_t::iterator audio_src_id_end = mLocalPlayingAudioSourceIDs.end(); - while (audio_src_id_iter != audio_src_id_end) + while (audio_src_id_iter != mLocalPlayingAudioSourceIDs.end()) { const LLUUID& audio_src_id = *audio_src_id_iter; if (LLAudioSource* audio_source = gAudiop->findAudioSource(audio_src_id); !audio_source || audio_source->isDone()) @@ -454,14 +451,13 @@ void NACLFloaterExploreSounds::blacklistSound(FSAssetBlacklist::eBlacklistFlag f region_name = cur_region->getName(); } - blacklist_avatar_name_cache_connection_map_t::iterator it = mBlacklistAvatarNameCacheConnections.find(item.mOwnerID); - if (it != mBlacklistAvatarNameCacheConnections.end()) + if (auto found = mBlacklistAvatarNameCacheConnections.find(item.mOwnerID); found != mBlacklistAvatarNameCacheConnections.end()) { - if (it->second.connected()) + if (found->second.connected()) { - it->second.disconnect(); + found->second.disconnect(); } - mBlacklistAvatarNameCacheConnections.erase(it); + mBlacklistAvatarNameCacheConnections.erase(found); } LLAvatarNameCache::callback_connection_t cb = LLAvatarNameCache::get(item.mOwnerID, boost::bind(&NACLFloaterExploreSounds::onBlacklistAvatarNameCacheCallback, this, _1, _2, item.mAssetID, region_name, flag)); mBlacklistAvatarNameCacheConnections.insert(std::make_pair(item.mOwnerID, cb)); @@ -470,14 +466,13 @@ void NACLFloaterExploreSounds::blacklistSound(FSAssetBlacklist::eBlacklistFlag f void NACLFloaterExploreSounds::onBlacklistAvatarNameCacheCallback(const LLUUID& av_id, const LLAvatarName& av_name, const LLUUID& asset_id, const std::string& region_name, FSAssetBlacklist::eBlacklistFlag flag) { - blacklist_avatar_name_cache_connection_map_t::iterator it = mBlacklistAvatarNameCacheConnections.find(av_id); - if (it != mBlacklistAvatarNameCacheConnections.end()) + if (auto found = mBlacklistAvatarNameCacheConnections.find(av_id); found != mBlacklistAvatarNameCacheConnections.end()) { - if (it->second.connected()) + if (found->second.connected()) { - it->second.disconnect(); + found->second.disconnect(); } - mBlacklistAvatarNameCacheConnections.erase(it); + mBlacklistAvatarNameCacheConnections.erase(found); } FSAssetBlacklist::getInstance()->addNewItemToBlacklist(asset_id, av_name.getCompleteName(), region_name, LLAssetType::AT_SOUND, flag); } diff --git a/indra/newview/NACLfloaterexploresounds.h b/indra/newview/NACLfloaterexploresounds.h index 090b9f9469..ff2a36d453 100644 --- a/indra/newview/NACLfloaterexploresounds.h +++ b/indra/newview/NACLfloaterexploresounds.h @@ -23,7 +23,7 @@ public: bool tick() override; - LLSoundHistoryItem getItem(const LLUUID& itemID); + LLSoundHistoryItem getItem(const LLUUID& itemID) const; private: virtual ~NACLFloaterExploreSounds();