From d1d42701f5ccbef6c2cd38369f0e70e47bee4ee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Liru=20F=C3=A6rs?= Date: Sat, 11 Jan 2020 21:00:16 -0500 Subject: [PATCH] Fix taya's linux crash, thanks to taya and router! Crash was due to invalidated iterator --- indra/newview/scriptcounter.cpp | 53 +++++++++++++++++---------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/indra/newview/scriptcounter.cpp b/indra/newview/scriptcounter.cpp index 24e173c45..b29527794 100644 --- a/indra/newview/scriptcounter.cpp +++ b/indra/newview/scriptcounter.cpp @@ -139,34 +139,35 @@ void ScriptCounter::inventoryChanged(LLViewerObject* obj, LLInventoryObject::obj if (inv) { - for (auto i = inv->begin(), end = inv->end(); i != end; ++i) - if (LLInventoryObject* asset = *i) - if (asset->getType() == LLAssetType::AT_LSL_TEXT) + uuid_vec_t ids; + + for (auto asset : *inv) + { + const LLUUID& id = asset->getUUID(); + if (asset->getType() == LLAssetType::AT_LSL_TEXT && id.notNull()) + { + ++scriptcount; + if (doDelete) + ids.push_back(id); + else { - const LLUUID& id = asset->getUUID(); - ++scriptcount; - if (doDelete) - { - if (id.notNull()) - { - //LL_INFOS() << "Deleting script " << id << " in " << objid << LL_ENDL; - obj->removeInventory(id); - --i; // Avoid iteration when removing, everything has shifted - end = inv->end(); - } - } - else - { - LLMessageSystem* msg = gMessageSystem; - msg->newMessageFast(_PREHASH_GetScriptRunning); - msg->nextBlockFast(_PREHASH_Script); - msg->addUUIDFast(_PREHASH_ObjectID, obj->getID()); - msg->addUUIDFast(_PREHASH_ItemID, id); - msg->sendReliable(obj->getRegion()->getHost()); - sCheckMap[id] = this; - ++checking; - } + LLMessageSystem* msg = gMessageSystem; + msg->newMessageFast(_PREHASH_GetScriptRunning); + msg->nextBlockFast(_PREHASH_Script); + msg->addUUIDFast(_PREHASH_ObjectID, obj->getID()); + msg->addUUIDFast(_PREHASH_ItemID, id); + msg->sendReliable(obj->getRegion()->getHost()); + sCheckMap[id] = this; + ++checking; } + } + } + + for (const auto& id : ids) + { + //LL_INFOS() << "Deleting script " << id << " in " << objid << LL_ENDL; + obj->removeInventory(id); + } } summarize();