4545#endif
4646
4747extern U32 gOctreeMaxCapacity ;
48+ extern float gOctreeMinSize ;
4849extern U32 gOctreeReserveCapacity ;
4950#if LL_DEBUG
5051#define LL_OCTREE_PARANOIA_CHECK 0
@@ -404,7 +405,7 @@ class LLOctreeNode : public LLTreeNode<T>
404405 F32 size = mSize [0 ];
405406 F32 p_size = size * 2 .f ;
406407
407- return (radius <= 0 . 001f && size <= 0 . 001f ) ||
408+ return (radius <= gOctreeMinSize && size <= gOctreeMinSize ) ||
408409 (radius <= p_size && radius > size);
409410 }
410411
@@ -511,7 +512,7 @@ class LLOctreeNode : public LLTreeNode<T>
511512 // is it here?
512513 if (isInside (data->getPositionGroup ()))
513514 {
514- if (((getElementCount () < gOctreeMaxCapacity && contains (data->getBinRadius ())) ||
515+ if (((( getElementCount () < gOctreeMaxCapacity || getSize ()[ 0 ] <= gOctreeMinSize ) && contains (data->getBinRadius ())) ||
515516 (data->getBinRadius () > getSize ()[0 ] && parent && parent->getElementCount () >= gOctreeMaxCapacity )))
516517 { // it belongs here
517518 /* mElementCount++;
@@ -566,8 +567,9 @@ class LLOctreeNode : public LLTreeNode<T>
566567 LLVector4a val;
567568 val.setSub (center, getCenter ());
568569 val.setAbs (val);
569-
570- S32 lt = val.lessThan (LLVector4a::getEpsilon ()).getGatheredBits () & 0x7 ;
570+ LLVector4a min_diff (gOctreeMinSize );
571+
572+ S32 lt = val.lessThan (min_diff).getGatheredBits () & 0x7 ;
571573
572574 if ( lt == 0x7 )
573575 {
@@ -616,17 +618,15 @@ class LLOctreeNode : public LLTreeNode<T>
616618 }
617619#endif
618620
621+ llassert (size[0 ] >= gOctreeMinSize *0 .5f );
619622 // make the new kid
620623 child = new LLOctreeNode<T>(center, size, this );
621624 addChild (child);
622625
623626 child->insert (data);
624627 }
625628 }
626- // Singu note: now that we allow wider range in octree, discard them here
627- // if they fall out of range
628- #if 0
629- else
629+ else if (parent)
630630 {
631631 // it's not in here, give it to the root
632632 OCT_ERRS << " Octree insertion failed, starting over from root!" << LL_ENDL;
@@ -639,12 +639,15 @@ class LLOctreeNode : public LLTreeNode<T>
639639 parent = node->getOctParent ();
640640 }
641641
642- if(node != this)
643- {
644- node->insert(data);
645- }
642+ node->insert (data);
643+ }
644+ else
645+ {
646+ // It's not in here, and we are root.
647+ // LLOctreeRoot::insert() should have expanded
648+ // root by now, something is wrong
649+ OCT_ERRS << " Octree insertion failed! Root expansion failed." << LL_ENDL;
646650 }
647- #endif
648651
649652 return false ;
650653 }
@@ -1050,10 +1053,15 @@ class LLOctreeRoot : public LLOctreeNode<T>
10501053 {
10511054 LLOctreeNode<T>::insert (data);
10521055 }
1053- else
1056+ else if (node-> isInside (data-> getPositionGroup ()))
10541057 {
10551058 node->insert (data);
10561059 }
1060+ else
1061+ {
1062+ // calling node->insert(data) will return us to root
1063+ OCT_ERRS << " Failed to insert data at child node" << LL_ENDL;
1064+ }
10571065 }
10581066 else if (this ->getChildCount () == 0 )
10591067 {
@@ -1088,6 +1096,8 @@ class LLOctreeRoot : public LLOctreeNode<T>
10881096 this ->setSize (size2);
10891097 this ->updateMinMax ();
10901098
1099+ llassert (size[0 ] >= gOctreeMinSize );
1100+
10911101 // copy our children to a new branch
10921102 LLOctreeNode<T>* newnode = new LLOctreeNode<T>(center, size, this );
10931103
0 commit comments