Index: /GTP/trunk/Lib/Vis/Preprocessing/src/SubdivisionCandidate.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/SubdivisionCandidate.h	(revision 1297)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/SubdivisionCandidate.h	(revision 1302)
@@ -25,8 +25,4 @@
 
 	SubdivisionCandidate(): mRenderCostDecrease(0) {};
-
-	/*SubdivisionCandidate(const AxisAlignedPlane &plane): 
-	mSplitPlane(plane), mRenderCostDecrease(0)
-	{}*/
 
 	virtual void EvalPriority() = 0;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp	(revision 1291)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp	(revision 1302)
@@ -529,6 +529,6 @@
 							  geom);
 
+	// evaluate the priority of this traversal data
 	EvalPriority(tData);
-
 
 	// first node is kd node, i.e. an axis aligned box
@@ -750,5 +750,6 @@
 {
 	return
-		(mOutOfMemory 
+		(0
+		|| mOutOfMemory 
 		|| (mBspStats.Leaves() >= mMaxViewCells) 
 		|| (mGlobalCostMisses >= mTermGlobalCostMissTolerance)
@@ -2316,6 +2317,6 @@
 
 #ifdef _DEBUG
-	Debug << axis << " " << pvsSize << " " << pvsBack << " " << pvsFront << endl;
-	Debug << pFront << " " << pBack << " " << pOverall << endl;
+	Debug << "axis: " << axis << " " << pvsSize << " " << pvsBack << " " << pvsFront << endl;
+	Debug << "p: " << pFront << " " << pBack << " " << pOverall << endl;
 #endif
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp	(revision 1299)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp	(revision 1302)
@@ -521,5 +521,5 @@
 		// use a small box outside of the scene
 		box.Scale(Vector3(0.1f,0.5f,0.5f));
-		box.Translate(Vector3(Magnitude(mKdTree->GetBox().Size())*0.5, 0, 0));
+		box.Translate(Vector3(Magnitude(mKdTree->GetBox().Size())*0.5f, 0, 0));
 	  } else {
 		float s = box.Size(0);
@@ -692,5 +692,5 @@
 	  GenerateRays(mRssSamplesPerPass*ratios[0], RSS_BASED_DISTRIBUTION, rays);
 
-	  rays.NormalizePdf((int)rays.size());
+	  rays.NormalizePdf((float)rays.size());
 	  
 	  CastRays(rays, tmpVssRays);
@@ -702,5 +702,5 @@
 #endif
 	  times[0] = TimeDiff(t1, GetTime());
-	  nrays[0] = rays.size();
+	  nrays[0] = (int)rays.size();
 	  
 	  mStats<<"#RssRelContrib"<<endl<<contributions[0]/nrays[0]<<endl;
@@ -713,5 +713,5 @@
 		GenerateRays(mRssSamplesPerPass*ratios[1], SPATIAL_BOX_BASED_DISTRIBUTION, rays);
 		CastRays(rays, tmpVssRays);
-		castRays += rays.size();
+		castRays += (int)rays.size();
 #if ADD_RAYS_IN_PLACE 
 		contributions[1] = mViewCellsManager->ComputeSampleContributions(tmpVssRays, true, false);
@@ -720,5 +720,5 @@
 #endif
 	  times[1] = TimeDiff(t1, GetTime());
-	  nrays[1] = rays.size();
+	  nrays[1] = (int)rays.size();
 
 	  mStats<<"#SpatialRelContrib"<<endl<<contributions[1]/nrays[1]<<endl;
@@ -735,5 +735,5 @@
 		GenerateRays(mRssSamplesPerPass*ratios[2], DIRECTION_BASED_DISTRIBUTION, rays);
 		CastRays(rays, tmpVssRays);
-		castRays += rays.size();
+		castRays += (int)rays.size();
 #if ADD_RAYS_IN_PLACE 
 		contributions[2] = mViewCellsManager->ComputeSampleContributions(tmpVssRays, true, false);
@@ -742,5 +742,5 @@
 #endif
 		times[2] = TimeDiff(t1, GetTime());
-		nrays[2] = rays.size();
+		nrays[2] = (int)rays.size();
 		
 		mStats<<"#DirectionalRelContrib"<<endl<<contributions[2]/nrays[2]<<endl;
@@ -790,5 +790,5 @@
 	  CastRays(rays, vssRays);
 	  cout<<"done."<<endl;
-	  castRays += rays.size();
+	  castRays += (int)rays.size();
 	  if (mUseViewcells) {
 		/// compute view cell contribution of rays
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 1297)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 1302)
@@ -36,6 +36,6 @@
 class VspTree;
 class KdTreeStatistics;
-class SubdivisionCandidate;
-class VspSubdivisionCandidate;
+//class SubdivisionCandidate;
+//class VspSubdivisionCandidate;
 
 /** View space partition statistics.
@@ -482,10 +482,7 @@
 	};
 
-	//typedef std::priority_queue<VspTraversalData> VspOspTraversalQueue;
-
 	/** Default constructor creating an empty tree.
 	*/ 
 	VspTree();
-
 	/** Default destructor.
 	*/
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1298)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1302)
@@ -29,7 +29,5 @@
 int BvhNode::sReservedMailboxes = 1;
 
-
 BvHierarchy *BvHierarchy::BvhSubdivisionCandidate::sBvHierarchy = NULL;
-
 
 
@@ -85,5 +83,5 @@
 
 BvhLeaf::BvhLeaf(const AxisAlignedBox3 &bbox):
-BvhNode(bbox)
+BvhNode(bbox), mSubdivisionCandidate(NULL)
 {
 }
@@ -430,10 +428,12 @@
 
 	const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume();
-	const float oldRenderCost = 
-		splitCandidate.mParentData.mProbability * (float)leaf->mObjects.size() / viewSpaceVol;
+	const float oldProp = EvalViewCellsVolume(leaf->mObjects);
+	const float oldProp2 = splitCandidate.mParentData.mProbability; //Debug << "here8 " << (oldProp - oldProp2) / viewSpaceVol << "  " << oldProp  / viewSpaceVol << " " << oldProp2  / viewSpaceVol << endl;
+
+	const float oldRenderCost = oldProp * (float)leaf->mObjects.size() / viewSpaceVol;
 
 	// compute global decrease in render cost
 	float newRenderCost = EvalRenderCost(splitCandidate.mParentData,
-									     splitCandidate.mFrontObjects, 
+									     splitCandidate.mFrontObjects,
 										 splitCandidate.mBackObjects);
 
@@ -445,5 +445,5 @@
 	splitCandidate.SetRenderCostDecrease(renderCostDecr);
 
-#if 0
+#if 1
 	const float priority = (float)-splitCandidate.mParentData.mDepth;
 #else	
@@ -452,5 +452,4 @@
 	const float factor = mRenderCostDecreaseWeight;
 	const float priority = factor * renderCostDecr + (1.0f - factor) * oldRenderCost;
-
 #endif
 
@@ -476,5 +475,5 @@
 	return (0
 		|| (mBvhStats.Leaves() >= mTermMaxLeaves)
-		|| (mGlobalCostMisses >= mTermGlobalCostMissTolerance)
+		//|| (mGlobalCostMisses >= mTermGlobalCostMissTolerance)
 		//|| mOutOfMemory 
 		);
@@ -574,7 +573,9 @@
 	}
 
-	const float oldRenderCost = tData.mProbability * (float)tData.mNode->mObjects.size();
-	const float newRenderCost = 
-		EvalRenderCost(tData, objectsFront, objectsBack);
+	const float oldProp = EvalViewCellsVolume(tData.mNode->mObjects);
+	//const float oldProp2 = tData.mProbability; Debug << "here65 " << oldProp - oldProp2 << endl;
+
+	const float oldRenderCost = oldProp * (float)tData.mNode->mObjects.size();
+	const float newRenderCost = EvalRenderCost(tData, objectsFront, objectsBack);
 
 	const float ratio = newRenderCost / oldRenderCost;
@@ -960,12 +961,10 @@
 
 	//-- pvs rendering heuristics
-	const float newRenderCost = nObjectsFront * pFront + 
-								nObjectsBack * pBack;
-
+	const float newRenderCost = nObjectsFront * pFront + nObjectsBack * pBack;
+	/*
 	const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume();
-	/*Debug << "\nbvh render cost\n" 
+	Debug << "\nbvh render cost\n" 
 		  << "back p: " << pBack / viewSpaceVol << " front p " << pFront / viewSpaceVol << endl
 		  << "new rc: " << newRenderCost / viewSpaceVol << endl;*/
-		 
 
 	return newRenderCost;
@@ -1100,4 +1099,5 @@
 
 	Debug << "collecting " << (int)viewCells.size() << " dirty candidates" << endl;
+
 	for (vit = viewCells.begin(); vit != vit_end; ++ vit)
 	{
@@ -1105,4 +1105,5 @@
 		VspLeaf *leaf = vc->mLeaf;
 		SubdivisionCandidate *candidate = leaf->GetSubdivisionCandidate();
+		Debug << "here100 candidate: " << candidate << " type: " << candidate->Type() << endl;
 		
 		dirtyList.push_back(leaf->GetSubdivisionCandidate());
@@ -1301,5 +1302,5 @@
 
 	// compute bounding box from objects
-	// we assume that root was already created
+	// note: we assume that root was already created
 	mBoundingBox = mRoot->GetBoundingBox();
 	BvhLeaf *bvhleaf = dynamic_cast<BvhLeaf *>(mRoot);
@@ -1311,5 +1312,4 @@
 	AssociateObjectsWithRays(sampleRays);
 	
-
 	// probabilty is voume of all "seen" view cells
 #if 1
@@ -1326,7 +1326,6 @@
 		new BvhSubdivisionCandidate(oData);
 
-	//UpdateViewCellsPvs(kdleaf, rays);
-
 	EvalSubdivisionCandidate(*oSubdivisionCandidate);
+	bvhleaf->SetSubdivisionCandidate(oSubdivisionCandidate);
 
 	const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume();
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1293)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1302)
@@ -5703,5 +5703,5 @@
 	}
 
-	Debug << "\nhere295 " << rc / mHierarchyManager->GetVspTree()->GetBoundingBox().GetVolume() << endl;
+	Debug << "\nrendercost hack: " << rc / mHierarchyManager->GetVspTree()->GetBoundingBox().GetVolume() << endl;
 	mViewCellsTree->ExportStats(fileName);
 	cout << "finished" << endl;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 1297)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 1302)
@@ -35,5 +35,5 @@
 class VspTree;
 class ViewCellsContainer;
-class BvhSubdivisionCandidate;
+//class BvhSubdivisionCandidate;
 
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1297)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1302)
@@ -23,4 +23,5 @@
 
 
+
 namespace GtpVisibilityPreprocessor {
 
@@ -32,10 +33,9 @@
 
 VspTree *VspTree::VspSubdivisionCandidate::sVspTree = NULL;
-
+int VspNode::sMailId = 1;
 
 // variable for debugging volume contribution for heuristics
 static float debugVol;
 
-int VspNode::sMailId = 1;
 
 // pvs penalty can be different from pvs size
@@ -53,5 +53,4 @@
 		return (float)upper;
 	}
-
 	return (float)pvs;
 }
@@ -299,5 +298,5 @@
 
 
-VspLeaf::VspLeaf(): mViewCell(NULL), mPvs(NULL)
+VspLeaf::VspLeaf(): mViewCell(NULL), mPvs(NULL), mSubdivisionCandidate(NULL)
 {
 }
@@ -554,5 +553,5 @@
 		// || mOutOfMemory
 		|| (mVspStats.Leaves() >= mMaxViewCells)
-        || (mGlobalCostMisses >= mTermGlobalCostMissTolerance) 
+        //|| (mGlobalCostMisses >= mTermGlobalCostMissTolerance) 
 		);
 
@@ -630,6 +629,6 @@
 	VspSubdivisionCandidate *sc = 
 		dynamic_cast<VspSubdivisionCandidate *>(splitCandidate);
+
 	VspTraversalData &tData = sc->mParentData;
-
 	VspNode *newNode = tData.mNode;
 
@@ -735,6 +734,5 @@
 
 	// max cost threshold violated?
-	splitCandidate.mMaxCostMisses = 
-		maxCostRatioViolated  ? 
+	splitCandidate.mMaxCostMisses = maxCostRatioViolated  ? 
 			splitCandidate.mParentData.mMaxCostMisses + 1:
 			splitCandidate.mParentData.mMaxCostMisses;
@@ -749,8 +747,7 @@
 	splitCandidate.SetRenderCostDecrease(renderCostDecr);
 
-#if 0
+#if 1
 	const float priority = (float)-splitCandidate.mParentData.mDepth;
-#else	
-
+#else
 	// take render cost of node into account 
 	// otherwise danger of being stuck in a local minimum!!
@@ -785,4 +782,5 @@
 
 	//-- compute pvs
+
 	frontData.mPvs = EvalPvsSize(*frontData.mRays);
 	backData.mPvs = EvalPvsSize(*backData.mRays);
@@ -815,8 +813,4 @@
     
 	VspInterior *interior = new VspInterior(splitPlane);
-
-#ifdef _DEBUG
-	Debug << interior << endl;
-#endif+
 
 
@@ -1196,5 +1190,4 @@
 	float minSum = 1e20f;
 
-	
 	// if no good split can be found, take mid split
 	position = minBox + 0.5f * sizeBox;
@@ -1209,5 +1202,4 @@
 
 	//-- traverse through visibility events
-
 	vector<SortableEntry>::const_iterator ci, ci_end = mLocalSubdivisionCandidates->end();
 
@@ -1373,5 +1365,4 @@
 	Intersectable::NewMail(3);
 	KdLeaf::NewMail(3);
-	//for (int i=0;i<25;++i) BvhLeaf::NewMail();
 	BvhLeaf::NewMail(3);
 
@@ -1392,11 +1383,7 @@
 		// evaluate contribution of ray endpoint to front and back pvs
 		// with respect to the classification
-		//Debug << "mail1:  " << BvhLeaf::sMailId << endl;
 		UpdateContributionsToPvs(*ray, true, cf, pvsFront, pvsBack, totalPvs);	
-		//Debug << "mail2:  " << BvhLeaf::sMailId << endl;
 		UpdateContributionsToPvs(*ray, false, cf, pvsFront, pvsBack, totalPvs);
-		//Debug << "mail3:  " << BvhLeaf::sMailId << endl;
-	}
-
+	}
 
 	AxisAlignedBox3 frontBox;
@@ -1412,9 +1399,9 @@
 
 	//-- pvs rendering heuristics
+
 	const int lowerPvsLimit = mViewCellsManager->GetMinPvsSize();
 	const int upperPvsLimit = mViewCellsManager->GetMaxPvsSize();
 
-	//-- only render cost heuristics or combined with standard deviation
-
+	// only render cost heuristics or combined with standard deviation
 	const float penaltyOld = EvalPvsPenalty((int)totalPvs, lowerPvsLimit, upperPvsLimit);
     const float penaltyFront = EvalPvsPenalty((int)pvsFront, lowerPvsLimit, upperPvsLimit);
@@ -1484,6 +1471,6 @@
 	
 #ifdef _DEBUG
-	Debug << axis << " " << pvsSize << " " << pvsBack << " " << pvsFront << endl;
-	Debug << pFront << " " << pBack << " " << pOverall << endl;
+	Debug << "axis: " << axis << " " << pvsSize << " " << pvsBack << " " << pvsFront << endl;
+	Debug << "p: " << pFront << " " << pBack << " " << pOverall << endl;
 #endif
 
@@ -2662,4 +2649,5 @@
 	VspSubdivisionCandidate *splitCandidate = new VspSubdivisionCandidate(vData);
     EvalSubdivisionCandidate(*splitCandidate);
+	leaf->SetSubdivisionCandidate(splitCandidate);
 
 	mTotalCost = (float)pvsSize;
@@ -2674,4 +2662,5 @@
 									vector<SubdivisionCandidate *> &dirtyList) const
 {
+
 	Intersectable *obj;
 	Vector3 pt;
@@ -2679,5 +2668,5 @@
 
 	ray.GetSampleData(isTermination, pt, &obj, &node);
-
+	
 	if (!obj) return;
 
@@ -2693,9 +2682,17 @@
 				dirtyList.push_back(leaf->mSubdivisionCandidate);
 			}
-
 			break;
 		}
 	case HierarchyManager::BV_BASED_OBJ_SUBDIV:
 		{
+			BvhLeaf *leaf = mHierarchyManager->mBvHierarchy->GetLeaf(obj);
+
+			if (!leaf->Mailed())
+			{
+				leaf->Mail();
+				dirtyList.push_back(leaf->GetSubdivisionCandidate());
+				Debug << "here120 candidate: " << leaf->GetSubdivisionCandidate() << " type: " << leaf->GetSubdivisionCandidate()->Type() << endl;
+			}
+			break;
 		}
 		break;
@@ -2714,5 +2711,5 @@
 	KdLeaf::NewMail();
 	BvhLeaf::NewMail();
-
+	
 	RayInfoContainer::const_iterator rit, rit_end = tData.mRays->end();
 
@@ -2721,5 +2718,5 @@
 	{
 		VssRay *ray = (*rit).mRay;
-	
+		
 		CollectDirtyCandidate(*ray, true, dirtyList);
 		CollectDirtyCandidate(*ray, false, dirtyList);
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/VssTree.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/VssTree.cpp	(revision 1297)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/VssTree.cpp	(revision 1302)
@@ -801,10 +801,10 @@
   // C = ct_div_ci  + (ql*rl + qr*rr)/queries
 	
-  int rl=0, rr = leaf->rays.size();
-  int pl=0, pr = leaf->GetPvsSize();
+  int rl=0, rr = (int)leaf->rays.size();
+  int pl=0, pr = (int)leaf->GetPvsSize();
   float sizeBox = maxBox - minBox;
 	
-  float minBand = minBox + 0.1*(maxBox - minBox);
-  float maxBand = minBox + 0.9*(maxBox - minBox);
+  float minBand = minBox + 0.1f*(maxBox - minBox);
+  float maxBand = minBox + 0.9f*(maxBox - minBox);
 	
   float minRatio = 1e20f;
@@ -901,5 +901,5 @@
   splitCandidates->clear();
   
-  int requestedSize = 2*(node->rays.size());
+  int requestedSize = 2*((int)node->rays.size());
   // creates a sorted split candidates array
   if (splitCandidates->capacity() > 500000 &&
@@ -1304,5 +1304,5 @@
 	
 		if (removeAllScheduledRays) {
-		  int tail = leaf->rays.size()-1;
+		  int tail = (int)leaf->rays.size()-1;
 
 		  for (int i=0; i < (int)(leaf->rays.size()); i++) {
@@ -1664,5 +1664,5 @@
 	  VssTreeLeaf *leaf = (VssTreeLeaf *)node;
 	  float c = leaf->GetImportance();
-	  int num = (c*ratioPerLeaf + 0.5f);
+	  int num = int(c*ratioPerLeaf + 0.5f);
 	  //			cout<<num<<" ";
 
@@ -1683,5 +1683,5 @@
   }
 
-  return rays.size();
+  return (int)rays.size();
 }
 
@@ -1975,5 +1975,5 @@
 	}
   }
-  return rays.size();
+  return (int)rays.size();
 }
 
@@ -2009,6 +2009,6 @@
   }
   
-  return rays.size();
-}
-
-}
+  return (int)rays.size();
+}
+
+}
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1298)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1302)
@@ -232,5 +232,5 @@
 		|| (mHierarchyStats.Leaves() >= mTermMaxLeaves) 
 		//|| (mGlobalCostMisses >= mTermGlobalCostMissTolerance)
-		//||	candidate->GlobalTerminationCriteriaMet()
+		||	candidate->GlobalTerminationCriteriaMet()
 		);
 }
@@ -269,13 +269,13 @@
 						*objectSpaceRays);
 
-
 	cout << "Constructing view space / object space tree ... \n";
 	const long startTime = GetTime();	
 	
 	const bool repairQueue = true;
+	//const bool repairQueue = false;
+
 	// process object space candidates
 	RunConstruction(repairQueue);
-
-	cout << "finished in " << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl;
+	cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
 
 	mVspTree->mVspStats.Stop();
@@ -424,8 +424,8 @@
 			if (repair) RepairQueue();
 
-			cout << "candidate: " << mCurrentCandidate->Type() << ", priority: " 
-				 << mCurrentCandidate->GetPriority() << endl;
-		}
-
+			Debug << "candidate: " << mCurrentCandidate->Type() << ", priority: " 
+				  << mCurrentCandidate->GetPriority() << endl;
+		}
+		
 		DEL_PTR(mCurrentCandidate);
 	}
@@ -457,4 +457,6 @@
 
 			mBvHierarchy->CollectDirtyCandidates(sc, dirtyList);
+
+sc->mParentData.mNode->SetSubdivisionCandidate(NULL); // HACK
 			break;
 		}
@@ -471,16 +473,19 @@
 
 	mVspTree->CollectDirtyCandidates(sc, dirtyList);
+
+sc->mParentData.mNode->SetSubdivisionCandidate(NULL); // HACK
 }
 
 
 void HierarchyManager::CollectDirtyCandidates(SubdivisionCandidateContainer &dirtyList)
-{	
+{
 	// we have either a object space or view space split
 	if (mCurrentCandidate->Type() == SubdivisionCandidate::VIEW_SPACE)
 	{
+		Debug << "collecting candidates after view space split" << endl;
 		CollectViewSpaceDirtyList(dirtyList);
 	}
 	else // object space split
-	{	
+	{	Debug << "collecting candidates after object space split" << endl;
 		CollectObjectSpaceDirtyList(dirtyList);
 	}
@@ -509,18 +514,35 @@
 	// collect list of "dirty" candidates
 	vector<SubdivisionCandidate *> dirtyList;
+	Debug << "collecting dirty candidates" << endl;
 	CollectDirtyCandidates(dirtyList);
 	
 	//-- reevaluate the dirty list
 	vector<SubdivisionCandidate *>::const_iterator sit, sit_end = dirtyList.end();
+	
+	Debug << "collected " << (int)dirtyList.size() << " candidates" << endl;
 
 	for (sit = dirtyList.begin(); sit != sit_end; ++ sit)
 	{
 		SubdivisionCandidate* sc = *sit;
-		// erase from queue
-		mTQueue.Erase(sc);
-		// reevaluate
-		sc->EvalPriority();
-		// reinsert
-		mTQueue.Push(sc);
+		float rcd = sc->GetRenderCostDecrease();
+		Debug << "here6 " << rcd << endl;
+		Debug << "here84 " << endl;
+		Debug << "here7 " << sc << endl;
+		Debug << "here90 " << sc->GetPosition() << endl;
+		Debug << "here91 " << sc->Type() << endl;
+		//Debug << "here1191" << sc->Type() << endl;
+		//Debug << "sc: " << sc << " " << sc->GetPosition() << " " << sc->Type() << endl;
+		
+		Debug << "here11" << endl;
+		mTQueue.Erase(sc); // erase from queue
+		Debug << "here2" << endl;
+
+		sc->EvalPriority(); // reevaluate
+		
+	/*	cout << "render cost decrease diff " << rcd - sc->GetRenderCostDecrease() 
+			 << " old: " << rcd << " new " << sc->GetRenderCostDecrease()
+			 << " type " << sc->Type() << endl;*/
+
+		mTQueue.Push(sc); // reinsert
 	}
 }
