From a1d0d67e05c45bdc1a7a8bb0aad79772a2a94f6e Mon Sep 17 00:00:00 2001
From: Dave Parks <davep@lindenlab.com>
Date: Fri, 15 Jun 2012 16:07:06 -0500
Subject: [PATCH] MAINT-775 Fix for particle index pool corruption on teleport.

---
 indra/newview/llappviewer.cpp   |  4 ++++
 indra/newview/llface.cpp        |  7 ++-----
 indra/newview/llface.h          |  1 +
 indra/newview/llvopartgroup.cpp | 10 +++++++---
 indra/newview/llvopartgroup.h   |  1 +
 5 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index 89994e505b5..3fabb48e214 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -89,6 +89,7 @@
 #include "lllogininstance.h"
 #include "llprogressview.h"
 #include "llvocache.h"
+#include "llvopartgroup.h"
 #include "llweb.h"
 #include "llsecondlifeurls.h"
 #include "llupdaterservice.h"
@@ -673,6 +674,9 @@ bool LLAppViewer::init()
 	// initialize SSE options
 	LLVector4a::initClass();
 
+	//initialize particle index pool
+	LLVOPartGroup::initClass();
+
 	// Need to do this initialization before we do anything else, since anything
 	// that touches files should really go through the lldir API
 	gDirUtilp->initAppDirs("SecondLife");
diff --git a/indra/newview/llface.cpp b/indra/newview/llface.cpp
index 9acdee702b0..f5b217d5392 100644
--- a/indra/newview/llface.cpp
+++ b/indra/newview/llface.cpp
@@ -202,13 +202,10 @@ void LLFace::destroy()
 		mTexture->removeFace(this) ;
 	}
 	
-	if (mDrawablep.notNull() &&
-		(mDrawablep->getRenderType() == LLPipeline::RENDER_TYPE_PARTICLES ||
-		mDrawablep->getRenderType() == LLPipeline::RENDER_TYPE_HUD_PARTICLES) &&
-		mIndicesIndex != 0xFFFFFFFF)
+	if (isState(LLFace::PARTICLE))
 	{
 		LLVOPartGroup::freeVBSlot(getGeomIndex()/4);
-		mIndicesIndex = 0xFFFFFFFF;
+		clearState(LLFace::PARTICLE);
 	}
 
 	if (mDrawPoolp)
diff --git a/indra/newview/llface.h b/indra/newview/llface.h
index 76ea5c853ac..3babc13c2ed 100644
--- a/indra/newview/llface.h
+++ b/indra/newview/llface.h
@@ -79,6 +79,7 @@ class LLFace
 		USE_FACE_COLOR	= 0x0010,
 		TEXTURE_ANIM	= 0x0020, 
 		RIGGED			= 0x0040,
+		PARTICLE		= 0x0080,
 	};
 
 	static void initClass();
diff --git a/indra/newview/llvopartgroup.cpp b/indra/newview/llvopartgroup.cpp
index 02282fd6a65..9cce68fff69 100644
--- a/indra/newview/llvopartgroup.cpp
+++ b/indra/newview/llvopartgroup.cpp
@@ -52,8 +52,7 @@ LLPointer<LLVertexBuffer> LLVOPartGroup::sVB = NULL;
 S32 LLVOPartGroup::sVBSlotFree[];
 S32* LLVOPartGroup::sVBSlotCursor = NULL;
 
-//static
-void LLVOPartGroup::restoreGL()
+void LLVOPartGroup::initClass()
 {
 	for (S32 i = 0; i < LL_MAX_PARTICLE_COUNT; ++i)
 	{
@@ -61,7 +60,11 @@ void LLVOPartGroup::restoreGL()
 	}
 
 	sVBSlotCursor = sVBSlotFree;
+}
 
+//static
+void LLVOPartGroup::restoreGL()
+{
 	sVB = new LLVertexBuffer(VERTEX_DATA_MASK, GL_STREAM_DRAW_ARB);
 	U32 count = LL_MAX_PARTICLE_COUNT;
 	sVB->allocateBuffer(count*4, count*6, true);
@@ -626,7 +629,7 @@ void LLParticlePartition::getGeometry(LLSpatialGroup* group)
 		LLFace* facep = *i;
 		LLAlphaObject* object = (LLAlphaObject*) facep->getViewerObject();
 
-		if (facep->getIndicesStart() == 0xFFFFFFFF)
+		if (!facep->isState(LLFace::PARTICLE))
 		{ //set the indices of this face
 			S32 idx = LLVOPartGroup::findAvailableVBSlot();
 			if (idx >= 0)
@@ -635,6 +638,7 @@ void LLParticlePartition::getGeometry(LLSpatialGroup* group)
 				facep->setIndicesIndex(idx*6);
 				facep->setVertexBuffer(LLVOPartGroup::sVB);
 				facep->setPoolType(LLDrawPool::POOL_ALPHA);
+				facep->setState(LLFace::PARTICLE);
 			}
 			else
 			{
diff --git a/indra/newview/llvopartgroup.h b/indra/newview/llvopartgroup.h
index 6160bceb24a..43b2844f07b 100644
--- a/indra/newview/llvopartgroup.h
+++ b/indra/newview/llvopartgroup.h
@@ -45,6 +45,7 @@ class LLVOPartGroup : public LLAlphaObject
 	static S32 sVBSlotFree[LL_MAX_PARTICLE_COUNT];
 	static S32* sVBSlotCursor;
 
+	static void initClass();
 	static void restoreGL();
 	static void destroyGL();
 	static S32 findAvailableVBSlot();
-- 
GitLab