From 7b5618aeaeb4df31bd3f9436e067b26fb5be866b Mon Sep 17 00:00:00 2001
From: Xiaohong Bao <bao@lindenlab.com>
Date: Thu, 22 Aug 2013 12:22:34 -0600
Subject: [PATCH] fix for SH-4400: Interesting: Side effect 1 of unloading
 culled objects.

---
 indra/newview/lldrawable.cpp     | 16 ++-------------
 indra/newview/lldrawable.h       |  1 -
 indra/newview/llvieweroctree.cpp |  2 +-
 indra/newview/llvieweroctree.h   |  2 --
 indra/newview/llvocache.cpp      | 35 ++++++++++++++++++++++++--------
 indra/newview/llvocache.h        |  6 ++++--
 6 files changed, 34 insertions(+), 28 deletions(-)

diff --git a/indra/newview/lldrawable.cpp b/indra/newview/lldrawable.cpp
index ad3df55ef1e..a480eed2e76 100755
--- a/indra/newview/lldrawable.cpp
+++ b/indra/newview/lldrawable.cpp
@@ -1058,12 +1058,8 @@ bool LLDrawable::isRecentlyVisible() const
 
 	if(!vis)
 	{
-		LLviewerOctreeGroup* group = getGroup();
-		if (group && group->isRecentlyVisible())
-		{
-			LLViewerOctreeEntryData::setVisible();
-			vis = TRUE ;
-		}
+		const U32 MIN_VIS_FRAME_RANGE = 2 ; //two frames:the current one and the last one.
+		vis = (sCurVisible - getVisible() < MIN_VIS_FRAME_RANGE);
 	}
 
 	return vis ;
@@ -1140,14 +1136,6 @@ LLSpatialPartition* LLDrawable::getSpatialPartition()
 	return retval;
 }
 
-//virtual
-U32 LLDrawable::getMinFrameRange() const
-{
-	const U32 MIN_VIS_FRAME_RANGE = 2 ; //two frames:the current one and the last one.
-
-	return MIN_VIS_FRAME_RANGE ;
-}
-
 //=======================================
 // Spatial Partition Bridging Drawable
 //=======================================
diff --git a/indra/newview/lldrawable.h b/indra/newview/lldrawable.h
index efb3e1d89d6..b94f663f21e 100755
--- a/indra/newview/lldrawable.h
+++ b/indra/newview/lldrawable.h
@@ -194,7 +194,6 @@ class LLDrawable
 
 	LLSpatialPartition* getSpatialPartition();
 	
-	virtual U32 getMinFrameRange()const;
 	void removeFromOctree();
 
 	void setSpatialBridge(LLSpatialBridge* bridge) { mSpatialBridge = (LLDrawable*) bridge; }
diff --git a/indra/newview/llvieweroctree.cpp b/indra/newview/llvieweroctree.cpp
index 637505a826e..481befdb44b 100644
--- a/indra/newview/llvieweroctree.cpp
+++ b/indra/newview/llvieweroctree.cpp
@@ -409,7 +409,7 @@ bool LLViewerOctreeEntryData::isRecentlyVisible() const
 		return true;
 	}
 
-	return (sCurVisible - mEntry->mVisible < getMinFrameRange());
+	return false;
 }
 
 void LLViewerOctreeEntryData::setVisible() const
diff --git a/indra/newview/llvieweroctree.h b/indra/newview/llvieweroctree.h
index 0cd02062233..e610db96eb9 100644
--- a/indra/newview/llvieweroctree.h
+++ b/indra/newview/llvieweroctree.h
@@ -149,8 +149,6 @@ class LLViewerOctreeEntryData : public LLRefCount
 	
 	virtual void setOctreeEntry(LLViewerOctreeEntry* entry);
 
-	virtual U32  getMinFrameRange()const = 0;
-
 	F32                  getBinRadius() const   {return mEntry->getBinRadius();}
 	const LLVector4a*    getSpatialExtents() const;
 	LLviewerOctreeGroup* getGroup()const;
diff --git a/indra/newview/llvocache.cpp b/indra/newview/llvocache.cpp
index 3bd71e2648d..2430fa556a1 100755
--- a/indra/newview/llvocache.cpp
+++ b/indra/newview/llvocache.cpp
@@ -238,12 +238,6 @@ void LLVOCacheEntry::setState(U32 state)
 	}
 }
 
-//virtual 
-U32  LLVOCacheEntry::getMinFrameRange()const
-{
-	return mMinFrameRange;
-}
-
 void LLVOCacheEntry::addChild(LLVOCacheEntry* entry)
 {
 	llassert(entry != NULL);
@@ -371,6 +365,28 @@ BOOL LLVOCacheEntry::writeToFile(LLAPRFile* apr_file) const
 	return success ;
 }
 
+bool LLVOCacheEntry::isRecentlyVisible() const
+{
+	bool vis = LLViewerOctreeEntryData::isRecentlyVisible();
+
+	if(!vis)
+	{
+		vis = (sCurVisible - getVisible() < mMinFrameRange);
+	}
+
+	if(!vis && !mParentID && mSceneContrib > 0.f)
+	{
+		//projection area: mSceneContrib
+
+		//squared distance
+		const F32 SQUARED_CUT_OFF_DIST = 225.0; //15m
+		F32 rad = getBinRadius();
+		vis = (rad * rad / mSceneContrib > SQUARED_CUT_OFF_DIST);
+	}
+
+	return vis;
+}
+
 void LLVOCacheEntry::calcSceneContribution(const LLVector3& camera_origin, bool needs_update, U32 last_update)
 {
 	if(!needs_update && getVisible() >= last_update)
@@ -387,8 +403,11 @@ void LLVOCacheEntry::calcSceneContribution(const LLVector3& camera_origin, bool
 	lookAt.setSub(center, origin);
 	F32 squared_dist = lookAt.dot3(lookAt).getF32();
 
-	F32 rad = getBinRadius();
-	mSceneContrib = rad * rad / squared_dist;
+	if(squared_dist > 0.f)
+	{
+		F32 rad = getBinRadius();
+		mSceneContrib = rad * rad / squared_dist;
+	}
 
 	setVisible();
 }
diff --git a/indra/newview/llvocache.h b/indra/newview/llvocache.h
index 71be9de7598..4eca0834451 100755
--- a/indra/newview/llvocache.h
+++ b/indra/newview/llvocache.h
@@ -83,12 +83,14 @@ class LLVOCacheEntry : public LLViewerOctreeEntryData
 	bool hasState(U32 state)   {return mState & state;}
 	U32  getState() const      {return mState;}
 	
+	//virtual
+	bool isRecentlyVisible() const;
+
 	U32 getLocalID() const			{ return mLocalID; }
 	U32 getCRC() const				{ return mCRC; }
 	S32 getHitCount() const			{ return mHitCount; }
 	S32 getCRCChangeCount() const	{ return mCRCChangeCount; }
-	U32 getMinFrameRange()const;	
-
+	
 	void calcSceneContribution(const LLVector3& camera_origin, bool needs_update, U32 last_update);
 	void setSceneContribution(F32 scene_contrib) {mSceneContrib = scene_contrib;}
 	F32 getSceneContribution() const             { return mSceneContrib;}
-- 
GitLab