From f9d8467d1eed047e1c386adcb548cd05ff552d44 Mon Sep 17 00:00:00 2001 From: Ansariel Date: Sun, 25 Oct 2020 05:05:10 +0100 Subject: [PATCH] Crash fixes for internal AO contributed by Rye Mutt plus some additional minor refactoring --- indra/newview/aoengine.cpp | 88 +++++++++++++++++++++----------------- indra/newview/aoengine.h | 6 +-- 2 files changed, 51 insertions(+), 43 deletions(-) diff --git a/indra/newview/aoengine.cpp b/indra/newview/aoengine.cpp index 424af81590..603f69ad89 100644 --- a/indra/newview/aoengine.cpp +++ b/indra/newview/aoengine.cpp @@ -189,12 +189,12 @@ void AOEngine::setLastOverriddenMotion(const LLUUID& motion) } } -BOOL AOEngine::foreignAnimations() +bool AOEngine::foreignAnimations() { // checking foreign animations only makes sense when smart sit is enabled if (!mCurrentSet->getSmart()) { - return FALSE; + return false; } // get the seat the avatar is sitting on @@ -202,14 +202,14 @@ BOOL AOEngine::foreignAnimations() if (!agentRoot) { // this should not happen, ever - return FALSE; + return false; } LLUUID seat = agentRoot->getID(); if (seat == gAgentID) { LL_DEBUGS("AOEngine") << "Not checking for foreign animation when not sitting." << LL_ENDL; - return FALSE; + return false; } LL_DEBUGS("AOEngine") << "Checking for foreign animation on seat " << seat << LL_ENDL; @@ -221,26 +221,27 @@ BOOL AOEngine::foreignAnimations() if (sourceIterator->first != gAgentID) { // find the source object where the animation came from - LLViewerObject* source=gObjectList.findObject(sourceIterator->first); + LLViewerObject* source = gObjectList.findObject(sourceIterator->first); // proceed if it's not an attachment - if(!source->isAttachment()) + if (source && !source->isAttachment()) { LL_DEBUGS("AOEngine") << "Source " << sourceIterator->first << " is running animation " << sourceIterator->second << LL_ENDL; // get the source's root prim - LLViewerObject* sourceRoot=dynamic_cast(source->getRoot()); + LLViewerObject* sourceRoot = dynamic_cast(source->getRoot()); // if the root prim is the same as the animation source, report back as TRUE if (sourceRoot && sourceRoot->getID() == seat) { LL_DEBUGS("AOEngine") << "foreign animation " << sourceIterator->second << " found on seat." << LL_ENDL; - return TRUE; + return true; } } } } - return FALSE; + + return false; } // map motion to underwater state, return nullptr if not applicable @@ -976,7 +977,7 @@ LLUUID AOEngine::addSet(const std::string& name, BOOL reload) return newUUID; } -BOOL AOEngine::createAnimationLink(const AOSet* set, AOSet::AOState* state, const LLInventoryItem* item) +bool AOEngine::createAnimationLink(const AOSet* set, AOSet::AOState* state, const LLInventoryItem* item) { LL_DEBUGS("AOEngine") << "Asset ID " << item->getAssetUUID() << " inventory id " << item->getUUID() << " category id " << state->mInventoryUUID << LL_ENDL; if (state->mInventoryUUID.isNull()) @@ -1009,7 +1010,7 @@ BOOL AOEngine::createAnimationLink(const AOSet* set, AOSet::AOState* state, cons if (state->mInventoryUUID.isNull()) { LL_DEBUGS("AOEngine") << "state inventory UUID not found, failing." << LL_ENDL; - return FALSE; + return false; } LLInventoryObject::const_object_list_t obj_array; @@ -1018,7 +1019,7 @@ BOOL AOEngine::createAnimationLink(const AOSet* set, AOSet::AOState* state, cons obj_array, LLPointer(NULL)); - return TRUE; + return true; } BOOL AOEngine::addAnimation(const AOSet* set, AOSet::AOState* state, const LLInventoryItem* item, BOOL reload) @@ -1042,57 +1043,64 @@ BOOL AOEngine::addAnimation(const AOSet* set, AOSet::AOState* state, const LLInv return TRUE; } -BOOL AOEngine::findForeignItems(const LLUUID& uuid) const +bool AOEngine::findForeignItems(const LLUUID& uuid) const { - BOOL moved = FALSE; + bool moved = false; LLInventoryModel::item_array_t* items; LLInventoryModel::cat_array_t* cats; gInventory.getDirectDescendentsOf(uuid, cats, items); - for (S32 index = 0; index < cats->size(); ++index) + + if (cats) { - // recurse into subfolders - if (findForeignItems(cats->at(index)->getUUID())) + for (const auto& cat : *cats) { - moved = TRUE; + if (findForeignItems(cat->getUUID())) + { + moved = true; + } } } // count backwards in case we have to remove items BOOL wasProtected = gSavedPerAccountSettings.getBOOL("LockAOFolders"); gSavedPerAccountSettings.setBOOL("LockAOFolders", FALSE); - for (S32 index = items->size() - 1; index >= 0; --index) - { - BOOL move = FALSE; - LLPointer item = items->at(index); - if (item->getIsLinkType()) + if (items) + { + for (S32 index = items->size() - 1; index >= 0; --index) { - if (item->getInventoryType() != LLInventoryType::IT_ANIMATION) + bool move = false; + + LLPointer item = items->at(index); + if (item->getIsLinkType()) { - LL_DEBUGS("AOEngine") << item->getName() << " is a link but does not point to an animation." << LL_ENDL; - move = TRUE; + if (item->getInventoryType() != LLInventoryType::IT_ANIMATION) + { + LL_DEBUGS("AOEngine") << item->getName() << " is a link but does not point to an animation." << LL_ENDL; + move = true; + } + else + { + LL_DEBUGS("AOEngine") << item->getName() << " is an animation link." << LL_ENDL; + } } else { - LL_DEBUGS("AOEngine") << item->getName() << " is an animation link." << LL_ENDL; + LL_DEBUGS("AOEngine") << item->getName() << " is not a link!" << LL_ENDL; + move = true; + } + + if (move) + { + moved = true; + gInventory.changeItemParent(item, gInventory.findCategoryUUIDForType(LLFolderType::FT_LOST_AND_FOUND), false); + LL_DEBUGS("AOEngine") << item->getName() << " moved to lost and found!" << LL_ENDL; } } - else - { - LL_DEBUGS("AOEngine") << item->getName() << " is not a link!" << LL_ENDL; - move = TRUE; - } - - if (move) - { - moved = TRUE; - LLInventoryModel* model = &gInventory; - model->changeItemParent(item, gInventory.findCategoryUUIDForType(LLFolderType::FT_LOST_AND_FOUND), FALSE); - LL_DEBUGS("AOEngine") << item->getName() << " moved to lost and found!" << LL_ENDL; - } } + gSavedPerAccountSettings.setBOOL("LockAOFolders", wasProtected); return moved; diff --git a/indra/newview/aoengine.h b/indra/newview/aoengine.h index 50f55519b5..dc5311c39a 100644 --- a/indra/newview/aoengine.h +++ b/indra/newview/aoengine.h @@ -171,7 +171,7 @@ class AOEngine void stopAllStandVariants(); void stopAllSitVariants(); - BOOL foreignAnimations(); + bool foreignAnimations(); AOSet::AOState* mapSwimming(const LLUUID& motion) const; AOSet::AOState* getStateForMotion(const LLUUID& motion) const; @@ -179,8 +179,8 @@ class AOEngine void saveSet(const AOSet* set); void saveState(const AOSet::AOState* state); - BOOL createAnimationLink(const AOSet* set, AOSet::AOState* state, const LLInventoryItem* item); - BOOL findForeignItems(const LLUUID& uuid) const; + bool createAnimationLink(const AOSet* set, AOSet::AOState* state, const LLInventoryItem* item); + bool findForeignItems(const LLUUID& uuid) const; void purgeFolder(const LLUUID& uuid) const; void onRegionChange();