From 20c578b7ae512e7c8128eb78f9dc4080fd556a91 Mon Sep 17 00:00:00 2001
From: Dave Parks <davep@lindenlab.com>
Date: Tue, 13 Dec 2022 11:40:14 -0600
Subject: [PATCH] SL-18808 Fix for highlight transparent texture missing.

---
 indra/newview/lldrawpoolalpha.cpp |  3 +--
 indra/newview/lldrawpoolwater.cpp |  2 +-
 indra/newview/llviewertexture.cpp | 16 +++++++++++++---
 indra/newview/llviewertexture.h   |  5 ++++-
 4 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp
index c09de14b238..6e0913705d6 100644
--- a/indra/newview/lldrawpoolalpha.cpp
+++ b/indra/newview/lldrawpoolalpha.cpp
@@ -315,8 +315,7 @@ void LLDrawPoolAlpha::renderDebugAlpha()
 	{
         gHighlightProgram.bind();
         gGL.diffuseColor4f(1, 0, 0, 1);
-        LLViewerFetchedTexture::sSmokeImagep->addTextureStats(1024.f * 1024.f);
-        gGL.getTexUnit(0)->bindFast(LLViewerFetchedTexture::sSmokeImagep);
+        gGL.getTexUnit(0)->bindFast(LLViewerFetchedTexture::getSmokeImage());
 
         renderAlphaHighlight(LLVertexBuffer::MAP_VERTEX |
             LLVertexBuffer::MAP_TEXCOORD0);
diff --git a/indra/newview/lldrawpoolwater.cpp b/indra/newview/lldrawpoolwater.cpp
index bc42dab1f2a..77da29061dc 100644
--- a/indra/newview/lldrawpoolwater.cpp
+++ b/indra/newview/lldrawpoolwater.cpp
@@ -743,7 +743,7 @@ void LLDrawPoolWater::renderWater()
 
 LLViewerTexture *LLDrawPoolWater::getDebugTexture()
 {
-	return LLViewerFetchedTexture::sSmokeImagep;
+    return LLViewerTextureManager::getFetchedTexture(IMG_SMOKE);
 }
 
 LLColor3 LLDrawPoolWater::getDebugColor() const
diff --git a/indra/newview/llviewertexture.cpp b/indra/newview/llviewertexture.cpp
index 0fd796afba7..c295bc76c0a 100644
--- a/indra/newview/llviewertexture.cpp
+++ b/indra/newview/llviewertexture.cpp
@@ -408,9 +408,6 @@ void LLViewerTextureManager::init()
 	LLViewerFetchedTexture::sDefaultImagep->dontDiscard();
 	LLViewerFetchedTexture::sDefaultImagep->setCategory(LLGLTexture::OTHER);
 
- 	LLViewerFetchedTexture::sSmokeImagep = LLViewerTextureManager::getFetchedTexture(IMG_SMOKE, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_UI);
-	LLViewerFetchedTexture::sSmokeImagep->setNoDelete();
-
 	image_raw = new LLImageRaw(32,32,3);
 	data = image_raw->getData();
 
@@ -1013,6 +1010,19 @@ const std::string& fttype_to_string(const FTType& fttype)
 //start of LLViewerFetchedTexture
 //----------------------------------------------------------------------------------------------
 
+//static 
+LLViewerFetchedTexture* LLViewerFetchedTexture::getSmokeImage()
+{
+    if (sSmokeImagep.isNull())
+    {
+        sSmokeImagep = LLViewerTextureManager::getFetchedTexture(IMG_SMOKE);
+    }
+
+    gPipeline.touchTexture(sSmokeImagep, 1024.f * 1024.f);
+
+    return sSmokeImagep;
+}
+
 LLViewerFetchedTexture::LLViewerFetchedTexture(const LLUUID& id, FTType f_type, const LLHost& host, BOOL usemipmaps)
 	: LLViewerTexture(id, usemipmaps),
 	mTargetHost(host)
diff --git a/indra/newview/llviewertexture.h b/indra/newview/llviewertexture.h
index 5fa5d893e71..facf05e52fb 100644
--- a/indra/newview/llviewertexture.h
+++ b/indra/newview/llviewertexture.h
@@ -525,9 +525,12 @@ class LLViewerFetchedTexture : public LLViewerTexture
 	static LLPointer<LLViewerFetchedTexture> sMissingAssetImagep;	// Texture to show for an image asset that is not in the database
 	static LLPointer<LLViewerFetchedTexture> sWhiteImagep;	// Texture to show NOTHING (whiteness)
 	static LLPointer<LLViewerFetchedTexture> sDefaultImagep; // "Default" texture for error cases, the only case of fetched texture which is generated in local.
-	static LLPointer<LLViewerFetchedTexture> sSmokeImagep; // Old "Default" translucent texture
 	static LLPointer<LLViewerFetchedTexture> sFlatNormalImagep; // Flat normal map denoting no bumpiness on a surface
 	static LLPointer<LLViewerFetchedTexture> sDefaultIrradiancePBRp; // PBR: irradiance
+
+    // not sure why, but something is iffy about the loading of this particular texture, use the accessor instead of accessing directly
+    static LLPointer<LLViewerFetchedTexture> sSmokeImagep; // Old "Default" translucent texture
+    static LLViewerFetchedTexture* getSmokeImage();
 };
 
 //
-- 
GitLab