Skip to content

Commit 9109310

Browse files
committed
Resolve race condition when removing/add attachments inside of a LLWearableHoldingPattern (see PR for details)
1 parent 49c607d commit 9109310

File tree

1 file changed

+50
-53
lines changed

1 file changed

+50
-53
lines changed

indra/newview/llappearancemgr.cpp

Lines changed: 50 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,6 @@ class LLWearableHoldingPattern
708708
found_list_t& getFoundList();
709709
void eraseTypeToLink(LLWearableType::EType type);
710710
void eraseTypeToRecover(LLWearableType::EType type);
711-
void setObjItems(const LLInventoryModel::item_array_t& items);
712711
void setGestItems(const LLInventoryModel::item_array_t& items);
713712
bool isMostRecent();
714713
void handleLateArrivals();
@@ -718,7 +717,6 @@ class LLWearableHoldingPattern
718717

719718
private:
720719
found_list_t mFoundList;
721-
LLInventoryModel::item_array_t mObjItems;
722720
LLInventoryModel::item_array_t mGestItems;
723721
typedef std::set<S32> type_set_t;
724722
type_set_t mTypesToRecover;
@@ -795,11 +793,6 @@ void LLWearableHoldingPattern::eraseTypeToRecover(LLWearableType::EType type)
795793
mTypesToRecover.erase(type);
796794
}
797795

798-
void LLWearableHoldingPattern::setObjItems(const LLInventoryModel::item_array_t& items)
799-
{
800-
mObjItems = items;
801-
}
802-
803796
void LLWearableHoldingPattern::setGestItems(const LLInventoryModel::item_array_t& items)
804797
{
805798
mGestItems = items;
@@ -905,55 +898,10 @@ void LLWearableHoldingPattern::onAllComplete()
905898

906899
if (isAgentAvatarValid())
907900
{
908-
LL_DEBUGS("Avatar") << self_av_string() << "Updating " << mObjItems.size() << " attachments" << LL_ENDL;
909-
LLAgentWearables::llvo_vec_t objects_to_remove;
910-
LLAgentWearables::llvo_vec_t objects_to_retain;
911-
LLInventoryModel::item_array_t items_to_add;
912-
913-
LLAgentWearables::findAttachmentsAddRemoveInfo(mObjItems,
914-
objects_to_remove,
915-
objects_to_retain,
916-
items_to_add);
917-
918-
LL_DEBUGS("Avatar") << self_av_string() << "Removing " << objects_to_remove.size()
919-
<< " attachments" << LL_ENDL;
920-
921-
// Here we remove the attachment pos overrides for *all*
922-
// attachments, even those that are not being removed. This is
923-
// needed to get joint positions all slammed down to their
924-
// pre-attachment states.
925-
gAgentAvatarp->clearAttachmentOverrides();
926-
927-
if (objects_to_remove.size() || items_to_add.size())
928-
{
929-
LL_DEBUGS("Avatar") << "ATT will remove " << objects_to_remove.size()
930-
<< " and add " << items_to_add.size() << " items" << LL_ENDL;
931-
}
932-
933-
// Take off the attachments that will no longer be in the outfit.
934-
LLAgentWearables::userRemoveMultipleAttachments(objects_to_remove);
935-
936901
// Update wearables.
937902
LL_INFOS("Avatar") << self_av_string() << "HP " << index() << " updating agent wearables with "
938903
<< mResolved << " wearable items " << LL_ENDL;
939904
LLAppearanceMgr::instance().updateAgentWearables(this);
940-
941-
// Restore attachment pos overrides for the attachments that
942-
// are remaining in the outfit.
943-
for (LLAgentWearables::llvo_vec_t::iterator it = objects_to_retain.begin();
944-
it != objects_to_retain.end();
945-
++it)
946-
{
947-
LLViewerObject *objectp = *it;
948-
if (!objectp->isAnimatedObject())
949-
{
950-
gAgentAvatarp->addAttachmentOverridesForObject(objectp);
951-
}
952-
}
953-
954-
// Add new attachments to match those requested.
955-
LL_DEBUGS("Avatar") << self_av_string() << "Adding " << items_to_add.size() << " attachments" << LL_ENDL;
956-
LLAgentWearables::userAttachMultipleAttachments(items_to_add);
957905
}
958906

959907
if (isFetchCompleted() && isMissingCompleted())
@@ -2584,6 +2532,56 @@ void LLAppearanceMgr::updateAppearanceFromCOF(bool enforce_item_restrictions,
25842532
<< " descendent_count " << cof->getDescendentCount()
25852533
<< " viewer desc count " << cof->getViewerDescendentCount() << LL_ENDL;
25862534
}
2535+
2536+
// Update attachments to match those requested.
2537+
if (isAgentAvatarValid())
2538+
{
2539+
LL_DEBUGS("Avatar") << self_av_string() << "Updating " << obj_items.size() << " attachments" << LL_ENDL;
2540+
LLAgentWearables::llvo_vec_t objects_to_remove;
2541+
LLAgentWearables::llvo_vec_t objects_to_retain;
2542+
LLInventoryModel::item_array_t items_to_add;
2543+
2544+
LLAgentWearables::findAttachmentsAddRemoveInfo(obj_items,
2545+
objects_to_remove,
2546+
objects_to_retain,
2547+
items_to_add);
2548+
2549+
LL_DEBUGS("Avatar") << self_av_string() << "Removing " << objects_to_remove.size()
2550+
<< " attachments" << LL_ENDL;
2551+
2552+
// Here we remove the attachment pos overrides for *all*
2553+
// attachments, even those that are not being removed. This is
2554+
// needed to get joint positions all slammed down to their
2555+
// pre-attachment states.
2556+
gAgentAvatarp->clearAttachmentOverrides();
2557+
2558+
if (objects_to_remove.size() || items_to_add.size())
2559+
{
2560+
LL_DEBUGS("Avatar") << "ATT will remove " << objects_to_remove.size()
2561+
<< " and add " << items_to_add.size() << " items" << LL_ENDL;
2562+
}
2563+
2564+
// Take off the attachments that will no longer be in the outfit.
2565+
LLAgentWearables::userRemoveMultipleAttachments(objects_to_remove);
2566+
2567+
// Restore attachment pos overrides for the attachments that
2568+
// are remaining in the outfit.
2569+
for (LLAgentWearables::llvo_vec_t::iterator it = objects_to_retain.begin();
2570+
it != objects_to_retain.end();
2571+
++it)
2572+
{
2573+
LLViewerObject *objectp = *it;
2574+
if (!objectp->isAnimatedObject())
2575+
{
2576+
gAgentAvatarp->addAttachmentOverridesForObject(objectp);
2577+
}
2578+
}
2579+
2580+
// Add new attachments to match those requested.
2581+
LL_DEBUGS("Avatar") << self_av_string() << "Adding " << items_to_add.size() << " attachments" << LL_ENDL;
2582+
LLAgentWearables::userAttachMultipleAttachments(items_to_add);
2583+
}
2584+
25872585
if(!wear_items.size())
25882586
{
25892587
LLNotificationsUtil::add("CouldNotPutOnOutfit");
@@ -2598,7 +2596,6 @@ void LLAppearanceMgr::updateAppearanceFromCOF(bool enforce_item_restrictions,
25982596
LLTimer hp_block_timer;
25992597
LLWearableHoldingPattern* holder = new LLWearableHoldingPattern;
26002598

2601-
holder->setObjItems(obj_items);
26022599
holder->setGestItems(gest_items);
26032600

26042601
// Note: can't do normal iteration, because if all the

0 commit comments

Comments
 (0)