From 7ce880150fe7d2f333f207b5c8ed5672c8c8cfb0 Mon Sep 17 00:00:00 2001
From: AndreyL ProductEngine <alihatskiy@productengine.com>
Date: Mon, 23 Apr 2018 23:31:23 +0300
Subject: MAINT-8574 Fixed Crash in LLVOVolume::markDead() + null checks in
 LLVOVolume::setLightTextureID()

---
 indra/newview/llvovolume.cpp | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp
index 9b0d9f4a7b..c1ecfd07c1 100644
--- a/indra/newview/llvovolume.cpp
+++ b/indra/newview/llvovolume.cpp
@@ -266,9 +266,10 @@ void LLVOVolume::markDead()
 		{
 			mSculptTexture->removeVolume(LLRender::SCULPT_TEX, this);
 		}
-		if (hasLightTexture())
+
+		if (mLightTexture.notNull())
 		{
-			getLightTexture()->removeVolume(LLRender::LIGHT_TEX, this);
+			mLightTexture->removeVolume(LLRender::LIGHT_TEX, this);
 		}
 	}
 	
@@ -2850,8 +2851,8 @@ void LLVOVolume::setLightTextureID(LLUUID id)
 		{
 			setParameterEntryInUse(LLNetworkData::PARAMS_LIGHT_IMAGE, TRUE, true);
 		}
-		else
-		{
+		else if (old_texturep)
+		{	
 			old_texturep->removeVolume(LLRender::LIGHT_TEX, this);
 		}
 		LLLightImageParams* param_block = (LLLightImageParams*) getParameterEntry(LLNetworkData::PARAMS_LIGHT_IMAGE);
@@ -2860,17 +2861,25 @@ void LLVOVolume::setLightTextureID(LLUUID id)
 			param_block->setLightTexture(id);
 			parameterChanged(LLNetworkData::PARAMS_LIGHT_IMAGE, true);
 		}
-		getLightTexture()->addVolume(LLRender::LIGHT_TEX, this); // new texture
+		LLViewerTexture* tex = getLightTexture();
+		if (tex)
+		{
+			tex->addVolume(LLRender::LIGHT_TEX, this); // new texture
+		}
+		else
+		{
+			LL_WARNS() << "Can't get light texture for ID " << id.asString() << LL_ENDL;
+		}
 	}
-	else
+	else if (hasLightTexture())
 	{
-		if (hasLightTexture())
+		if (old_texturep)
 		{
 			old_texturep->removeVolume(LLRender::LIGHT_TEX, this);
-			setParameterEntryInUse(LLNetworkData::PARAMS_LIGHT_IMAGE, FALSE, true);
-			parameterChanged(LLNetworkData::PARAMS_LIGHT_IMAGE, true);
-			mLightTexture = NULL;
 		}
+		setParameterEntryInUse(LLNetworkData::PARAMS_LIGHT_IMAGE, FALSE, true);
+		parameterChanged(LLNetworkData::PARAMS_LIGHT_IMAGE, true);
+		mLightTexture = NULL;
 	}		
 }
 
-- 
cgit v1.2.3