From 40a1154ec9e5b98bdeec408aa8cce7a10919d602 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Tue, 19 Jul 2022 19:56:16 +0300 Subject: [PATCH 1/4] SL-17640 Check account balance before uploading --- indra/newview/llmaterialeditor.cpp | 22 ++++++++++++++++++++-- indra/newview/llmaterialeditor.h | 1 + 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/indra/newview/llmaterialeditor.cpp b/indra/newview/llmaterialeditor.cpp index 4f8558277d..fe50689c1e 100644 --- a/indra/newview/llmaterialeditor.cpp +++ b/indra/newview/llmaterialeditor.cpp @@ -40,6 +40,7 @@ #include "llviewertexture.h" #include "llsdutil.h" #include "llselectmgr.h" +#include "llstatusbar.h" // can_afford_transaction() #include "llviewerinventory.h" #include "llviewerregion.h" #include "llvovolume.h" @@ -79,6 +80,7 @@ private: LLMaterialEditor::LLMaterialEditor(const LLSD& key) : LLPreview(key) , mHasUnsavedChanges(false) + , mExpectedUploadCost(0) { const LLInventoryItem* item = getItem(); if (item) @@ -366,8 +368,8 @@ void LLMaterialEditor::setHasUnsavedChanges(bool value) upload_texture_count++; } - S32 upload_cost = upload_texture_count * LLAgentBenefitsMgr::current().getTextureUploadCost(); - getChild("total_upload_fee")->setTextArg("[FEE]", llformat("%d", upload_cost)); + mExpectedUploadCost = upload_texture_count * LLAgentBenefitsMgr::current().getTextureUploadCost(); + getChild("total_upload_fee")->setTextArg("[FEE]", llformat("%d", mExpectedUploadCost)); } void LLMaterialEditor::setCanSaveAs(BOOL value) @@ -474,6 +476,14 @@ static U32 write_texture(const LLUUID& id, tinygltf::Model& model) void LLMaterialEditor::onClickSave() { + if (!can_afford_transaction(mExpectedUploadCost)) + { + LLSD args; + args["COST"] = llformat("%d", mExpectedUploadCost); + LLNotificationsUtil::add("ErrorCannotAffordUpload", args); + return; + } + applyToSelection(); saveIfNeeded(); } @@ -839,6 +849,14 @@ void LLMaterialEditor::refreshFromInventory(const LLUUID& new_item_id) void LLMaterialEditor::onClickSaveAs() { + if (!can_afford_transaction(mExpectedUploadCost)) + { + LLSD args; + args["COST"] = llformat("%d", mExpectedUploadCost); + LLNotificationsUtil::add("ErrorCannotAffordUpload", args); + return; + } + LLSD args; args["DESC"] = mMaterialName; diff --git a/indra/newview/llmaterialeditor.h b/indra/newview/llmaterialeditor.h index 6196e3d310..be376c9d2b 100644 --- a/indra/newview/llmaterialeditor.h +++ b/indra/newview/llmaterialeditor.h @@ -191,6 +191,7 @@ private: LLPointer mEmissiveJ2C; bool mHasUnsavedChanges; + S32 mExpectedUploadCost; std::string mMaterialName; }; From 206d8a0e3124caee7778c9a1e1d44a9aaa4150de Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Wed, 20 Jul 2022 18:50:14 +0300 Subject: [PATCH 2/4] SL-17690 Uploaded material asset references wrong texture UUIDs Upload textures first, then get ids and upload material on callback --- indra/newview/llmaterialeditor.cpp | 159 +++++++++++++++++++++++--- indra/newview/llmaterialeditor.h | 7 +- indra/newview/llviewerassetupload.cpp | 22 +++- indra/newview/llviewerassetupload.h | 7 +- 4 files changed, 173 insertions(+), 22 deletions(-) diff --git a/indra/newview/llmaterialeditor.cpp b/indra/newview/llmaterialeditor.cpp index fe50689c1e..47ae2ab4d1 100644 --- a/indra/newview/llmaterialeditor.cpp +++ b/indra/newview/llmaterialeditor.cpp @@ -57,6 +57,11 @@ #include +const std::string MATERIAL_ALBEDO_DEFAULT_NAME = "Albedo"; +const std::string MATERIAL_NORMAL_DEFAULT_NAME = "Normal"; +const std::string MATERIAL_METALLIC_DEFAULT_NAME = "Metallic Roughness"; +const std::string MATERIAL_EMISSIVE_DEFAULT_NAME = "Emissive"; + class LLMaterialEditorCopiedCallback : public LLInventoryCallback { public: @@ -81,6 +86,7 @@ LLMaterialEditor::LLMaterialEditor(const LLSD& key) : LLPreview(key) , mHasUnsavedChanges(false) , mExpectedUploadCost(0) + , mUploadingTexturesCount(0) { const LLInventoryItem* item = getItem(); if (item) @@ -644,9 +650,22 @@ bool LLMaterialEditor::decodeAsset(const std::vector& buffer) bool LLMaterialEditor::saveIfNeeded() { + if (mUploadingTexturesCount > 0) + { + // upload already in progress + // wait until textures upload + // will retry saving on callback + return true; + } + + if (saveTextures() > 0) + { + // started texture upload + setEnabled(false); + return true; + } + std::string buffer = getEncodedAsset(); - - saveTextures(); const LLInventoryItem* item = getItem(); // save it out to database @@ -1179,6 +1198,11 @@ void LLMaterialFilePicker::loadMaterial(const std::string& filename) { mME->mAlbedoFetched->forceToSaveRawImage(0, F32_MAX); albedo_id = mME->mAlbedoFetched->getID(); + + if (mME->mAlbedoName.empty()) + { + mME->mAlbedoName = MATERIAL_ALBEDO_DEFAULT_NAME; + } } LLUUID normal_id; @@ -1186,6 +1210,11 @@ void LLMaterialFilePicker::loadMaterial(const std::string& filename) { mME->mNormalFetched->forceToSaveRawImage(0, F32_MAX); normal_id = mME->mNormalFetched->getID(); + + if (mME->mNormalName.empty()) + { + mME->mNormalName = MATERIAL_NORMAL_DEFAULT_NAME; + } } LLUUID mr_id; @@ -1193,6 +1222,11 @@ void LLMaterialFilePicker::loadMaterial(const std::string& filename) { mME->mMetallicRoughnessFetched->forceToSaveRawImage(0, F32_MAX); mr_id = mME->mMetallicRoughnessFetched->getID(); + + if (mME->mMetallicRoughnessName.empty()) + { + mME->mMetallicRoughnessName = MATERIAL_METALLIC_DEFAULT_NAME; + } } LLUUID emissive_id; @@ -1200,6 +1234,11 @@ void LLMaterialFilePicker::loadMaterial(const std::string& filename) { mME->mEmissiveFetched->forceToSaveRawImage(0, F32_MAX); emissive_id = mME->mEmissiveFetched->getID(); + + if (mME->mEmissiveName.empty()) + { + mME->mEmissiveName = MATERIAL_EMISSIVE_DEFAULT_NAME; + } } mME->setAlbedoId(albedo_id); @@ -1526,7 +1565,7 @@ void LLMaterialEditor::inventoryChanged(LLViewerObject* object, } -void LLMaterialEditor::saveTexture(LLImageJ2C* img, const std::string& name, const LLUUID& asset_id) +void LLMaterialEditor::saveTexture(LLImageJ2C* img, const std::string& name, const LLUUID& asset_id, upload_callback_f cb) { if (asset_id.isNull() || img == nullptr @@ -1541,7 +1580,6 @@ void LLMaterialEditor::saveTexture(LLImageJ2C* img, const std::string& name, con U32 expected_upload_cost = LLAgentBenefitsMgr::current().getTextureUploadCost(); - LLAssetStorage::LLStoreAssetCallback callback; LLResourceUploadInfo::ptr_t uploadInfo(std::make_shared( buffer, @@ -1556,28 +1594,114 @@ void LLMaterialEditor::saveTexture(LLImageJ2C* img, const std::string& name, con LLFloaterPerms::getGroupPerms("Uploads"), LLFloaterPerms::getEveryonePerms("Uploads"), expected_upload_cost, - false)); + false, + cb)); - upload_new_resource(uploadInfo, callback, nullptr); + upload_new_resource(uploadInfo); } -void LLMaterialEditor::saveTextures() +S32 LLMaterialEditor::saveTextures() { - if (mAlbedoTextureUploadId == getAlbedoId()) + S32 work_count = 0; + LLSD key = getKey(); // must be locally declared for lambda's capture to work + if (mAlbedoTextureUploadId == getAlbedoId() && mAlbedoTextureUploadId.notNull()) { - saveTexture(mAlbedoJ2C, mAlbedoName, mAlbedoTextureUploadId); + mUploadingTexturesCount++; + work_count++; + saveTexture(mAlbedoJ2C, mAlbedoName, mAlbedoTextureUploadId, [key](LLUUID newAssetId, LLSD response) + { + LLMaterialEditor* me = LLFloaterReg::findTypedInstance("material_editor", key); + if (me) + { + if (response["success"].asBoolean()) + { + me->setAlbedoId(newAssetId); + } + else + { + // To make sure that we won't retry (some failures can cb immediately) + me->setAlbedoId(LLUUID::null); + } + me->mUploadingTexturesCount--; + + // try saving + me->saveIfNeeded(); + } + }); } - if (mNormalTextureUploadId == getNormalId()) + if (mNormalTextureUploadId == getNormalId() && mNormalTextureUploadId.notNull()) { - saveTexture(mNormalJ2C, mNormalName, mNormalTextureUploadId); + mUploadingTexturesCount++; + work_count++; + saveTexture(mNormalJ2C, mNormalName, mNormalTextureUploadId, [key](LLUUID newAssetId, LLSD response) + { + LLMaterialEditor* me = LLFloaterReg::findTypedInstance("material_editor", key); + if (me) + { + if (response["success"].asBoolean()) + { + me->setNormalId(newAssetId); + } + else + { + me->setNormalId(LLUUID::null); + } + me->setNormalId(newAssetId); + me->mUploadingTexturesCount--; + + // try saving + me->saveIfNeeded(); + } + }); } - if (mMetallicTextureUploadId == getMetallicRoughnessId()) + if (mMetallicTextureUploadId == getMetallicRoughnessId() && mMetallicTextureUploadId.notNull()) { - saveTexture(mMetallicRoughnessJ2C, mMetallicRoughnessName, mMetallicTextureUploadId); + mUploadingTexturesCount++; + work_count++; + saveTexture(mMetallicRoughnessJ2C, mMetallicRoughnessName, mMetallicTextureUploadId, [key](LLUUID newAssetId, LLSD response) + { + LLMaterialEditor* me = LLFloaterReg::findTypedInstance("material_editor", key); + if (me) + { + if (response["success"].asBoolean()) + { + me->setMetallicRoughnessId(newAssetId); + } + else + { + me->setMetallicRoughnessId(LLUUID::null); + } + me->mUploadingTexturesCount--; + + // try saving + me->saveIfNeeded(); + } + }); } - if (mEmissiveTextureUploadId == getEmissiveId()) + + if (mEmissiveTextureUploadId == getEmissiveId() && mEmissiveTextureUploadId.notNull()) { - saveTexture(mEmissiveJ2C, mEmissiveName, mEmissiveTextureUploadId); + mUploadingTexturesCount++; + work_count++; + saveTexture(mEmissiveJ2C, mEmissiveName, mEmissiveTextureUploadId, [key](LLUUID newAssetId, LLSD response) + { + LLMaterialEditor* me = LLFloaterReg::findTypedInstance("material_editor", LLSD(key)); + if (me) + { + if (response["success"].asBoolean()) + { + me->setEmissiveId(newAssetId); + } + else + { + me->setEmissiveId(LLUUID::null); + } + me->mUploadingTexturesCount--; + + // try saving + me->saveIfNeeded(); + } + }); } // discard upload buffers once textures have been saved @@ -1595,5 +1719,10 @@ void LLMaterialEditor::saveTextures() mNormalTextureUploadId.setNull(); mMetallicTextureUploadId.setNull(); mEmissiveTextureUploadId.setNull(); + + // asset storage can callback immediately, causing a decrease + // of mUploadingTexturesCount, report amount of work scheduled + // not amount of work remaining + return work_count; } diff --git a/indra/newview/llmaterialeditor.h b/indra/newview/llmaterialeditor.h index be376c9d2b..3da59c7f93 100644 --- a/indra/newview/llmaterialeditor.h +++ b/indra/newview/llmaterialeditor.h @@ -63,10 +63,12 @@ public: void inventoryChanged(LLViewerObject* object, LLInventoryObject::object_list_t* inventory, S32 serial_num, void* user_data) override; - void saveTexture(LLImageJ2C* img, const std::string& name, const LLUUID& asset_id); + typedef std::function upload_callback_f; + void saveTexture(LLImageJ2C* img, const std::string& name, const LLUUID& asset_id, upload_callback_f cb); // save textures to inventory if needed - void saveTextures(); + // returns amount of scheduled uploads + S32 saveTextures(); void onClickSave(); @@ -191,6 +193,7 @@ private: LLPointer mEmissiveJ2C; bool mHasUnsavedChanges; + S32 mUploadingTexturesCount; S32 mExpectedUploadCost; std::string mMaterialName; }; diff --git a/indra/newview/llviewerassetupload.cpp b/indra/newview/llviewerassetupload.cpp index c4211fcb19..8e1ebdf6fa 100644 --- a/indra/newview/llviewerassetupload.cpp +++ b/indra/newview/llviewerassetupload.cpp @@ -510,11 +510,13 @@ LLNewBufferedResourceUploadInfo::LLNewBufferedResourceUploadInfo( U32 groupPerms, U32 everyonePerms, S32 expectedCost, - bool show_inventory) : - LLResourceUploadInfo(name, description, compressionInfo, + bool show_inventory, + uploadFinish_f finish) + : LLResourceUploadInfo(name, description, compressionInfo, destinationType, inventoryType, - nextOWnerPerms, groupPerms, everyonePerms, expectedCost, show_inventory), - mBuffer(buffer) + nextOWnerPerms, groupPerms, everyonePerms, expectedCost, show_inventory) + , mBuffer(buffer) + , mFinishFn(finish) { setAssetType(assetType); setAssetId(asset_id); @@ -543,6 +545,18 @@ LLSD LLNewBufferedResourceUploadInfo::exportTempFile() return LLSD(); } +LLUUID LLNewBufferedResourceUploadInfo::finishUpload(LLSD &result) +{ + LLUUID newItemId = LLResourceUploadInfo::finishUpload(result); + + if (mFinishFn) + { + mFinishFn(result["new_asset"].asUUID(), result); + } + + return newItemId; +} + //========================================================================= LLBufferedAssetUploadInfo::LLBufferedAssetUploadInfo(LLUUID itemId, LLAssetType::EType assetType, std::string buffer, invnUploadFinish_f finish) : LLResourceUploadInfo(std::string(), std::string(), 0, LLFolderType::FT_NONE, LLInventoryType::IT_NONE, diff --git a/indra/newview/llviewerassetupload.h b/indra/newview/llviewerassetupload.h index 91ffa973fa..9eddcfbd0e 100644 --- a/indra/newview/llviewerassetupload.h +++ b/indra/newview/llviewerassetupload.h @@ -172,6 +172,8 @@ private: class LLNewBufferedResourceUploadInfo : public LLResourceUploadInfo { public: + typedef std::function uploadFinish_f; + LLNewBufferedResourceUploadInfo( const std::string& buffer, const LLAssetID& asset_id, @@ -185,15 +187,18 @@ public: U32 groupPerms, U32 everyonePerms, S32 expectedCost, - bool show_inventory = true); + bool show_inventory, + uploadFinish_f finish); virtual LLSD prepareUpload(); protected: virtual LLSD exportTempFile(); + virtual LLUUID finishUpload(LLSD &result); private: + uploadFinish_f mFinishFn; std::string mBuffer; }; From eaebe8fe70985f6d25cf883867f19617164ead81 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Fri, 29 Jul 2022 12:08:31 -0400 Subject: [PATCH 3/4] DRTVWR-559: Revert "Fix minor Mac build issues." Somehow this commit got into my local repository without showing up as a new commit relative to bitbucket. Try double-reverting it. This is the first one. This reverts commit 7772b5639a9bae2c4fbbcd2575355404c4bdca55. --- indra/newview/llinventorybridge.cpp | 4 ++-- indra/newview/llmaterialeditor.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/indra/newview/llinventorybridge.cpp b/indra/newview/llinventorybridge.cpp index 03c6996de6..d325831c8f 100644 --- a/indra/newview/llinventorybridge.cpp +++ b/indra/newview/llinventorybridge.cpp @@ -785,7 +785,7 @@ void LLInvFVBridge::getClipboardEntries(bool show_asset_id, if (obj) { - if (obj->getType() != LLAssetType::AT_CATEGORY) + if (obj->getType() != LLInventoryType::IT_CATEGORY) { items.push_back(std::string("Copy Separator")); } @@ -881,7 +881,7 @@ void LLInvFVBridge::getClipboardEntries(bool show_asset_id, } } - if (obj->getType() != LLAssetType::AT_CATEGORY) + if (obj->getType() != LLInventoryType::IT_CATEGORY) { items.push_back(std::string("Paste Separator")); } diff --git a/indra/newview/llmaterialeditor.h b/indra/newview/llmaterialeditor.h index 3da59c7f93..4df991be39 100644 --- a/indra/newview/llmaterialeditor.h +++ b/indra/newview/llmaterialeditor.h @@ -57,7 +57,7 @@ public: void setFromGLTFMaterial(LLGLTFMaterial* mat); - void loadAsset() override; + void loadAsset(); static void onLoadComplete(const LLUUID& asset_uuid, LLAssetType::EType type, void* user_data, S32 status, LLExtStat ext_status); From 842ed39584b3df814c290931d750a1bf3b982cf3 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Fri, 29 Jul 2022 12:10:05 -0400 Subject: [PATCH 4/4] DRTVWR-559: Revert "Revert "Fix minor Mac build issues."" Try to reapply the original commit in such a way that it can be pushed. This reverts commit eaebe8fe70985f6d25cf883867f19617164ead81. --- indra/newview/llinventorybridge.cpp | 4 ++-- indra/newview/llmaterialeditor.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/indra/newview/llinventorybridge.cpp b/indra/newview/llinventorybridge.cpp index d325831c8f..03c6996de6 100644 --- a/indra/newview/llinventorybridge.cpp +++ b/indra/newview/llinventorybridge.cpp @@ -785,7 +785,7 @@ void LLInvFVBridge::getClipboardEntries(bool show_asset_id, if (obj) { - if (obj->getType() != LLInventoryType::IT_CATEGORY) + if (obj->getType() != LLAssetType::AT_CATEGORY) { items.push_back(std::string("Copy Separator")); } @@ -881,7 +881,7 @@ void LLInvFVBridge::getClipboardEntries(bool show_asset_id, } } - if (obj->getType() != LLInventoryType::IT_CATEGORY) + if (obj->getType() != LLAssetType::AT_CATEGORY) { items.push_back(std::string("Paste Separator")); } diff --git a/indra/newview/llmaterialeditor.h b/indra/newview/llmaterialeditor.h index 4df991be39..3da59c7f93 100644 --- a/indra/newview/llmaterialeditor.h +++ b/indra/newview/llmaterialeditor.h @@ -57,7 +57,7 @@ public: void setFromGLTFMaterial(LLGLTFMaterial* mat); - void loadAsset(); + void loadAsset() override; static void onLoadComplete(const LLUUID& asset_uuid, LLAssetType::EType type, void* user_data, S32 status, LLExtStat ext_status);