Fix incorrect use cases of LLAvatarNameCache::get callback-overload: If name is in cache, callback is fired immediately and the returned connection is a default, not-connected connection which will be dangling in the callback connection maps

master
Ansariel 2025-06-19 01:48:43 +02:00
parent 60dfaeb3a8
commit 2725c7d0c7
7 changed files with 71 additions and 56 deletions

View File

@ -451,22 +451,22 @@ void NACLFloaterExploreSounds::blacklistSound(FSAssetBlacklist::eBlacklistFlag f
region_name = cur_region->getName();
}
if (auto found = mBlacklistAvatarNameCacheConnections.find(item.mOwnerID); found != mBlacklistAvatarNameCacheConnections.end())
if (LLAvatarName av_name; LLAvatarNameCache::get(item.mOwnerID, &av_name))
{
if (found->second.connected())
{
found->second.disconnect();
}
mBlacklistAvatarNameCacheConnections.erase(found);
FSAssetBlacklist::getInstance()->addNewItemToBlacklist(item.mAssetID, av_name.getCompleteName(), region_name, LLAssetType::AT_SOUND, flag);
}
else
{
// Create unique UUID here instead of avatar UUID because we might be blacklisting more than one sound of the same user
LLUUID requestId = LLUUID::generateNewID();
mBlacklistAvatarNameCacheConnections.try_emplace(requestId, LLAvatarNameCache::get(item.mOwnerID, boost::bind(&NACLFloaterExploreSounds::onBlacklistAvatarNameCacheCallback, this, requestId, _1, _2, item.mAssetID, region_name, flag)));
}
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));
}
}
void NACLFloaterExploreSounds::onBlacklistAvatarNameCacheCallback(const LLUUID& av_id, const LLAvatarName& av_name, const LLUUID& asset_id, const std::string& region_name, FSAssetBlacklist::eBlacklistFlag flag)
void NACLFloaterExploreSounds::onBlacklistAvatarNameCacheCallback(const LLUUID& request_id, const LLUUID& av_id, const LLAvatarName& av_name, const LLUUID& asset_id, const std::string& region_name, FSAssetBlacklist::eBlacklistFlag flag)
{
if (auto found = mBlacklistAvatarNameCacheConnections.find(av_id); found != mBlacklistAvatarNameCacheConnections.end())
if (auto found = mBlacklistAvatarNameCacheConnections.find(request_id); found != mBlacklistAvatarNameCacheConnections.end())
{
if (found->second.connected())
{

View File

@ -48,7 +48,7 @@ private:
typedef std::map<LLUUID, boost::signals2::connection> blacklist_avatar_name_cache_connection_map_t;
blacklist_avatar_name_cache_connection_map_t mBlacklistAvatarNameCacheConnections;
void onBlacklistAvatarNameCacheCallback(const LLUUID& av_id, const LLAvatarName& av_name, const LLUUID& asset_id, const std::string& region_name, FSAssetBlacklist::eBlacklistFlag flag);
void onBlacklistAvatarNameCacheCallback(const LLUUID& request_id, const LLUUID& av_id, const LLAvatarName& av_name, const LLUUID& asset_id, const std::string& region_name, FSAssetBlacklist::eBlacklistFlag flag);
};
#endif

View File

@ -881,23 +881,27 @@ void FSData::addAgents()
return;
}
for (std::map<LLUUID, S32>::iterator iter = mTeamAgents.begin(); iter != mTeamAgents.end(); ++iter)
for (const auto& [id, flags] : mTeamAgents)
{
if (iter->second & NO_SPAM)
if (flags & NO_SPAM)
{
LLUUID id = iter->first;
avatar_name_cache_connection_map_t::iterator it = mAvatarNameCacheConnections.find(id);
if (it != mAvatarNameCacheConnections.end())
if (LLAvatarName av_name; LLAvatarNameCache::get(id, &av_name))
{
if (it->second.connected())
{
it->second.disconnect();
}
mAvatarNameCacheConnections.erase(it);
onNameCache(id, av_name);
}
else
{
if (auto it = mAvatarNameCacheConnections.find(id); it != mAvatarNameCacheConnections.end())
{
if (it->second.connected())
{
it->second.disconnect();
}
mAvatarNameCacheConnections.erase(it);
}
LLAvatarNameCache::callback_connection_t cb = LLAvatarNameCache::get(id, boost::bind(&FSData::onNameCache, this, _1, _2));
mAvatarNameCacheConnections.insert(std::make_pair(id, cb));
mAvatarNameCacheConnections.try_emplace(id, LLAvatarNameCache::get(id, boost::bind(&FSData::onNameCache, this, _1, _2)));
}
}
}
}

View File

@ -648,8 +648,7 @@ void FSFloaterContacts::addFriend(const LLUUID& agent_id)
{
const LLRelationship* info = at.getBuddyInfo(agent_id);
LLUUID request_id = LLUUID::generateNewID();
LLAvatarNameCache::callback_connection_t conn = LLAvatarNameCache::get(agent_id, boost::bind(&FSFloaterContacts::updateFriendItem, this, agent_id, info, request_id));
mAvatarNameCacheConnections[request_id] = conn;
mAvatarNameCacheConnections.try_emplace(request_id, LLAvatarNameCache::get(agent_id, boost::bind(&FSFloaterContacts::updateFriendItem, this, agent_id, info, request_id)));
}
LLSD element;
@ -742,8 +741,7 @@ void FSFloaterContacts::updateFriendItem(const LLUUID& agent_id, const LLRelatio
if (!LLAvatarNameCache::get(agent_id, &av_name))
{
LLUUID request_id = LLUUID::generateNewID();
LLAvatarNameCache::callback_connection_t conn = LLAvatarNameCache::get(agent_id, boost::bind(&FSFloaterContacts::updateFriendItem, this, agent_id, info, request_id));
mAvatarNameCacheConnections[request_id] = conn;
mAvatarNameCacheConnections.try_emplace(request_id, LLAvatarNameCache::get(agent_id, boost::bind(&FSFloaterContacts::updateFriendItem, this, agent_id, info, request_id)));
}
// Name of the status icon to use
@ -1250,21 +1248,19 @@ void FSFloaterContacts::onColumnDisplayModeChanged(const std::string& settings_n
void FSFloaterContacts::onDisplayNameChanged()
{
listitem_vec_t items = mFriendsList->getAllData();
for (listitem_vec_t::iterator it = items.begin(); it != items.end(); ++it)
for (auto item : mFriendsList->getAllData())
{
LLAvatarName av_name;
if (LLAvatarNameCache::get((*it)->getUUID(), &av_name))
if (LLAvatarNameCache::get(item->getUUID(), &av_name))
{
(*it)->getColumn(LIST_FRIEND_USER_NAME)->setValue(av_name.getUserNameForDisplay());
(*it)->getColumn(LIST_FRIEND_DISPLAY_NAME)->setValue(av_name.getDisplayName());
(*it)->getColumn(LIST_FRIEND_NAME)->setValue(getFullName(av_name));
item->getColumn(LIST_FRIEND_USER_NAME)->setValue(av_name.getUserNameForDisplay());
item->getColumn(LIST_FRIEND_DISPLAY_NAME)->setValue(av_name.getDisplayName());
item->getColumn(LIST_FRIEND_NAME)->setValue(getFullName(av_name));
}
else
{
LLUUID request_id = LLUUID::generateNewID();
LLAvatarNameCache::callback_connection_t conn = LLAvatarNameCache::get((*it)->getUUID(), boost::bind(&FSFloaterContacts::setDirtyNames, this, request_id));
mAvatarNameCacheConnections[request_id] = conn;
mAvatarNameCacheConnections.try_emplace(request_id, LLAvatarNameCache::get(item->getUUID(), boost::bind(&FSFloaterContacts::setDirtyNames, this, request_id)));
}
}
mFriendsList->setNeedsSort();

View File

@ -767,15 +767,23 @@ void LGGContactSets::setPseudonym(const LLUUID& friend_id, std::string_view pseu
inst->fetch(friend_id);
LLVOAvatar::invalidateNameTag(friend_id);
if (auto it = mAvatarNameCacheConnections.find(friend_id); it != mAvatarNameCacheConnections.end())
if (LLAvatarName av_name; LLAvatarNameCache::get(friend_id, &av_name))
{
if (it->second.connected())
{
it->second.disconnect();
}
mAvatarNameCacheConnections.erase(it);
mChangedSignal(UPDATED_MEMBERS);
}
else
{
if (auto it = mAvatarNameCacheConnections.find(friend_id); it != mAvatarNameCacheConnections.end())
{
if (it->second.connected())
{
it->second.disconnect();
}
mAvatarNameCacheConnections.erase(it);
}
mAvatarNameCacheConnections.try_emplace(friend_id, LLAvatarNameCache::get(friend_id, boost::bind(&LGGContactSets::onAvatarNameCache, this, _1)));
}
mAvatarNameCacheConnections[friend_id] = LLAvatarNameCache::get(friend_id, boost::bind(&LGGContactSets::onAvatarNameCache, this, _1));
saveToDisk();
}
@ -802,15 +810,24 @@ void LGGContactSets::clearPseudonym(const LLUUID& friend_id, bool save_changes /
removeNonFriendFromList(friend_id, save_changes);
}
if (auto it = mAvatarNameCacheConnections.find(friend_id); it != mAvatarNameCacheConnections.end())
if (LLAvatarName av_name; LLAvatarNameCache::get(friend_id, &av_name))
{
if (it->second.connected())
{
it->second.disconnect();
}
mAvatarNameCacheConnections.erase(it);
mChangedSignal(UPDATED_MEMBERS);
}
mAvatarNameCacheConnections[friend_id] = LLAvatarNameCache::get(friend_id, boost::bind(&LGGContactSets::onAvatarNameCache, this, _1));
else
{
if (auto it = mAvatarNameCacheConnections.find(friend_id); it != mAvatarNameCacheConnections.end())
{
if (it->second.connected())
{
it->second.disconnect();
}
mAvatarNameCacheConnections.erase(it);
}
mAvatarNameCacheConnections.try_emplace(friend_id, LLAvatarNameCache::get(friend_id, boost::bind(&LGGContactSets::onAvatarNameCache, this, _1)));
}
if (save_changes)
{
saveToDisk();

View File

@ -1761,7 +1761,8 @@ bool LLNetMap::handleRightMouseDown(S32 x, S32 y, MASK mask)
LLMenuItemCallGL::Params p;
p.name = llformat("Profile Item %d", itAgent - mClosestAgentsToCursor.begin());
LLAvatarName avName; const LLUUID& idAgent = *itAgent;
LLAvatarName avName;
const LLUUID& idAgent = *itAgent;
if (LLAvatarNameCache::get(idAgent, &avName))
{
p.label = avName.getCompleteName();
@ -1778,7 +1779,7 @@ bool LLNetMap::handleRightMouseDown(S32 x, S32 y, MASK mask)
}
mAvatarNameCacheConnections.erase(it);
}
mAvatarNameCacheConnections[idAgent] = LLAvatarNameCache::get(idAgent, boost::bind(&LLNetMap::setAvatarProfileLabel, this, _1, _2, p.name.getValue()));
mAvatarNameCacheConnections.try_emplace(idAgent, LLAvatarNameCache::get(idAgent, boost::bind(&LLNetMap::setAvatarProfileLabel, this, _1, _2, p.name.getValue())));
}
p.on_click.function = boost::bind(&LLAvatarActions::showProfile, _2);
p.on_click.parameter = idAgent;

View File

@ -225,8 +225,7 @@ void PermissionsTracker::objectPropertiesCallback(LLMessageSystem* msg)
mPermissionsList[source_id].objectName = object_name;
mPermissionsList[source_id].ownerID = object_owner;
LLAvatarName avatar_name;
if (LLAvatarNameCache::get(object_owner, &avatar_name))
if (LLAvatarName avatar_name; LLAvatarNameCache::get(object_owner, &avatar_name))
{
LL_DEBUGS("PermissionsTracker") << "Found cached entry for owner " << object_owner.asString()
<< ": " << avatar_name.getCompleteName() << LL_ENDL;
@ -234,10 +233,8 @@ void PermissionsTracker::objectPropertiesCallback(LLMessageSystem* msg)
}
else if (mAvatarNameCacheConnections.find(object_owner) != mAvatarNameCacheConnections.end())
{
boost::signals2::connection cb_connection = LLAvatarNameCache::get(object_owner, boost::bind(&PermissionsTracker::avatarNameCallback, this, _1, _2));
mAvatarNameCacheConnections.insert(std::make_pair(object_owner, cb_connection));
LL_DEBUGS("PermissionsTracker") << "Requesting avatar name for owner " << object_owner.asString() << LL_ENDL;
mAvatarNameCacheConnections.try_emplace(object_owner, LLAvatarNameCache::get(object_owner, boost::bind(&PermissionsTracker::avatarNameCallback, this, _1, _2)));
}
}
}