summaryrefslogtreecommitdiff
path: root/indra/newview/llmodelpreview.cpp
diff options
context:
space:
mode:
authorErik Kundiman <erik@megapahit.org>2024-12-01 18:56:45 +0800
committerErik Kundiman <erik@megapahit.org>2024-12-01 18:56:45 +0800
commitfda6acb4be1145ac1dc6c33859d8a65dcfa8aecb (patch)
tree3eefe5eaa1415dc32b78d3125754801400dd7212 /indra/newview/llmodelpreview.cpp
parent99337674245aca9b01a4346b7f6bd5822c119168 (diff)
parentc02baded8464781fcb208676610727e677ac6907 (diff)
Merge remote-tracking branch 'secondlife/release/2024.09-ExtraFPS' into 2024.09-ExtraFPS
Diffstat (limited to 'indra/newview/llmodelpreview.cpp')
-rw-r--r--indra/newview/llmodelpreview.cpp43
1 files changed, 29 insertions, 14 deletions
diff --git a/indra/newview/llmodelpreview.cpp b/indra/newview/llmodelpreview.cpp
index e04262715d..64ea1710f5 100644
--- a/indra/newview/llmodelpreview.cpp
+++ b/indra/newview/llmodelpreview.cpp
@@ -555,7 +555,7 @@ void LLModelPreview::rebuildUploadData()
{
// in case user provided a missing file later
texture->setIsMissingAsset(false);
- texture->setLoadedCallback(LLModelPreview::textureLoadedCallback, 0, true, false, this, &mCallbackTextureList, false);
+ texture->setLoadedCallback(LLModelPreview::textureLoadedCallback, 0, true, false, new LLHandle<LLModelPreview>(getHandle()), &mCallbackTextureList, false);
texture->forceToSaveRawImage(0, F32_MAX);
texture->updateFetch();
if (mModelLoader)
@@ -784,6 +784,10 @@ void LLModelPreview::loadModel(std::string filename, S32 lod, bool force_disable
std::map<std::string, std::string> joint_alias_map;
getJointAliases(joint_alias_map);
+ LLHandle<LLModelPreview> preview_handle = getHandle();
+ auto load_textures_cb =
+ [preview_handle](LLImportMaterial& material, void* opaque) { return LLModelPreview::loadTextures(material, preview_handle); };
+
// three possible file extensions, .dae .gltf .glb
// check for .dae and if not then assume one of the .gl??
std::string filename_lc(filename);
@@ -795,7 +799,7 @@ void LLModelPreview::loadModel(std::string filename, S32 lod, bool force_disable
lod,
&LLModelPreview::loadedCallback,
&LLModelPreview::lookupJointByName,
- &LLModelPreview::loadTextures,
+ load_textures_cb,
&LLModelPreview::stateChangedCallback,
this,
mJointTransformMap,
@@ -812,7 +816,7 @@ void LLModelPreview::loadModel(std::string filename, S32 lod, bool force_disable
lod,
&LLModelPreview::loadedCallback,
&LLModelPreview::lookupJointByName,
- &LLModelPreview::loadTextures,
+ load_textures_cb,
&LLModelPreview::stateChangedCallback,
this,
mJointTransformMap,
@@ -3130,9 +3134,9 @@ LLJoint* LLModelPreview::lookupJointByName(const std::string& str, void* opaque)
return NULL;
}
-U32 LLModelPreview::loadTextures(LLImportMaterial& material, void* opaque)
+U32 LLModelPreview::loadTextures(LLImportMaterial& material, LLHandle<LLModelPreview> handle)
{
- if (material.mDiffuseMapFilename.size())
+ if (material.mDiffuseMapFilename.size() && !handle.isDead())
{
material.mOpaqueData = new LLPointer< LLViewerFetchedTexture >;
LLPointer< LLViewerFetchedTexture >& tex = (*reinterpret_cast< LLPointer< LLViewerFetchedTexture > * >(material.mOpaqueData));
@@ -3143,10 +3147,8 @@ U32 LLModelPreview::loadTextures(LLImportMaterial& material, void* opaque)
// file was loaded previosly, reload image to get potential changes
tex->clearFetchedResults();
}
- // Todo: might cause a crash if preview gets closed before we get the callback.
- // Use a callback list or guard callback in some way
- LLModelPreview* preview = (LLModelPreview*)opaque;
- tex->setLoadedCallback(LLModelPreview::textureLoadedCallback, 0, true, false, opaque, &preview->mCallbackTextureList, false);
+ LLModelPreview* preview = (LLModelPreview*)handle.get();
+ tex->setLoadedCallback(LLModelPreview::textureLoadedCallback, 0, true, false, new LLHandle<LLModelPreview>(handle), &preview->mCallbackTextureList, false);
tex->forceToSaveRawImage(0, F32_MAX);
material.setDiffuseMap(tex->getID()); // record tex ID
return 1;
@@ -4019,16 +4021,29 @@ void LLModelPreview::textureLoadedCallback(
bool final,
void* userdata)
{
- LLModelPreview* preview = (LLModelPreview*)userdata;
- preview->refresh();
+ if (!userdata)
+ return;
+
+ LLHandle<LLModelPreview>* handle = (LLHandle<LLModelPreview>*)userdata;
- if (final && preview->mModelLoader)
+ if (!handle->isDead())
{
- if (preview->mModelLoader->mNumOfFetchingTextures > 0)
+ LLModelPreview* preview = static_cast<LLModelPreview*>(handle->get());
+ preview->refresh();
+
+ if (final && preview->mModelLoader)
{
- preview->mModelLoader->mNumOfFetchingTextures--;
+ if (preview->mModelLoader->mNumOfFetchingTextures > 0)
+ {
+ preview->mModelLoader->mNumOfFetchingTextures--;
+ }
}
}
+
+ if (final || !success)
+ {
+ delete handle;
+ }
}
// static