Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/src/CoherentHierarchicalCullingManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/src/CoherentHierarchicalCullingManager.cpp	(revision 2555)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/src/CoherentHierarchicalCullingManager.cpp	(revision 2556)
@@ -191,9 +191,17 @@
 {
 	// parent was tested invisible in this frame
-    return ( 
+    const bool nodeInvalid = ( 
 		    mHierarchyInterface->GetParent(node) && 
 		    (mHierarchyInterface->LastVisited(node) == mHierarchyInterface->GetFrameId()) && 
 		    !mHierarchyInterface->IsNodeVisible(mHierarchyInterface->GetParent(node))
            );
+
+	
+	if (nodeInvalid)
+	{
+		CullingLogManager::GetSingleton()->LogMessage("node invalid");
+	}
+
+	return nodeInvalid;
 }
 //-----------------------------------------------------------------------
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/src/CoherentHierarchicalCullingPlusPlusManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/src/CoherentHierarchicalCullingPlusPlusManager.cpp	(revision 2555)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/src/CoherentHierarchicalCullingPlusPlusManager.cpp	(revision 2556)
@@ -10,9 +10,11 @@
 
 
-static const bool CULL_INVALID_NODES = false;
+static const bool CULL_INVALID_NODES = true;
+//static const bool CULL_INVALID_NODES = false;
+static const int MAX_INVISIBLE_NODES_SIZE = 20;
 
 //-----------------------------------------------------------------------
 CoherentHierarchicalCullingPlusPlusManager::CoherentHierarchicalCullingPlusPlusManager():
-mAssumedVisibility(0), mMaxInvisibleNodesSize(50)
+mAssumedVisibility(0), mMaxInvisibleNodesSize(MAX_INVISIBLE_NODES_SIZE)
 {
 }
@@ -20,5 +22,5 @@
 CoherentHierarchicalCullingPlusPlusManager::CoherentHierarchicalCullingPlusPlusManager(
 														const unsigned int assumedVisibility):
-mAssumedVisibility(assumedVisibility), mMaxInvisibleNodesSize(50)
+mAssumedVisibility(assumedVisibility), mMaxInvisibleNodesSize(MAX_INVISIBLE_NODES_SIZE)
 {
 }
@@ -43,11 +45,20 @@
 	//-- PART 1: process finished occlusion queries
 
-	while (!mHierarchyInterface->GetQueue()->empty() || !mQueryQueue.empty() ||
-		   !mInvisibleNodes.empty() || !mVisibleNodes.empty())
+	while (!mHierarchyInterface->GetQueue()->empty() || !mQueryQueue.empty()
+		   || !mInvisibleNodes.empty() 
+		   //|| !mVisibleNodes.empty()
+		   )
 	{
 		//////////
 		//-- only wait for result if there are no nodes to process
-
+#if 0
+		bool resultAvailable = true;
+		while (!mQueryQueue.empty() && 
+			   (NodeInvalid(mQueryQueue.front().first) ||
+			    mQueryQueue.front().second->GetQueryResult(
+				             visiblePixels, mHierarchyInterface->GetQueue()->empty())))
+#else
 		bool resultAvailable = false;
+
 		while (
 			   !mQueryQueue.empty() && 
@@ -56,4 +67,5 @@
 			   (resultAvailable = mQueryQueue.front().second->GetQueryResult(visiblePixels, false)))
 			   )
+#endif
 		{
 			HierarchyNode *node = mQueryQueue.front().first;
@@ -64,5 +76,5 @@
 
 			// during the wait time issue nodes from visible queue
-			while (!mVisibleNodes.empty() && !resultAvailable)
+			while (1 && !mVisibleNodes.empty() && !resultAvailable)
 			{
 				HierarchyNode *vn = mVisibleNodes.front();
@@ -175,6 +187,6 @@
 					else
 					{
-						mVisibleNodes.push(node);
-						//IssueQuery(node, false);
+						// mVisibleNodes.push(node);
+						IssueQuery(node, false);
 					}
 				}
@@ -194,5 +206,5 @@
 		}
 
-		
+		  // issue rest of nodes from nodes from invisible queue
 		if (mHierarchyInterface->GetQueue()->empty() && !mInvisibleNodes.empty())
 		{
@@ -209,13 +221,6 @@
 
         // issue rest of nodes from nodes from visible queue
-		if (mHierarchyInterface->GetQueue()->empty() && mQueryQueue.empty() && !mVisibleNodes.empty())
-		{
-			if (0)
-			{
-				std::stringstream d;
-				d << "vis nodes: " << (int)mVisibleNodes.size();
-				CullingLogManager::GetSingleton()->LogMessage(d.str());
-			}
-
+		if (0 && mHierarchyInterface->GetQueue()->empty() && mQueryQueue.empty() && !mVisibleNodes.empty())
+		{
 			while (!mVisibleNodes.empty())
 			{
@@ -227,5 +232,5 @@
 
 
-	if (0)
+	if (0 && !mVisibleNodes.empty())
 	{
 		std::stringstream d;
@@ -234,6 +239,51 @@
 	}
 	
-	// render rest
+    // render rest
 	mHierarchyInterface->RenderQueue();
+
+	// issue rest of nodes from nodes from visible queue
+	while (!mVisibleNodes.empty())
+	{
+		IssueQuery(mVisibleNodes.front(), false);
+		mVisibleNodes.pop();
+	}
+
+	int i = 0;
+
+	while (!mQueryQueue.empty() && 
+		    mQueryQueue.front().second->GetQueryResult(visiblePixels, true))
+	{
+		++ i;
+
+		HierarchyNode *node = mQueryQueue.front().first;
+		mQueryQueue.pop();
+
+		// tested visible
+		if (visiblePixels > mVisibilityThreshold)
+		{
+			// assing the #frames the node is assumed to stay visible
+			AssignAssumedVisibility(node);
+			mHierarchyInterface->PullUpVisibility(node);
+		}
+		else
+		{	
+			mHierarchyInterface->SetNodeVisible(node, false);
+
+			++ mNumQueryCulledNodes;
+
+			if (mVisualizeCulledNodes)
+				mHierarchyInterface->VisualizeCulledNode(node, QUERY_CULLED);
+		}
+
+		// update node's visited flag
+		mHierarchyInterface->SetLastVisited(node, mHierarchyInterface->GetFrameId());	
+	}
+
+	if (0)
+	{
+		std::stringstream d;
+		d << "tested: " << i << " nodes";
+		CullingLogManager::GetSingleton()->LogMessage(d.str());
+	}
 }
 //-----------------------------------------------------------------------
@@ -265,9 +315,15 @@
 
 	// parent was tested invisible in this frame
-    return ( 
-		    mHierarchyInterface->GetParent(node) && 
-		    (mHierarchyInterface->LastVisited(node) == mHierarchyInterface->GetFrameId()) && 
-		    !mHierarchyInterface->IsNodeVisible(mHierarchyInterface->GetParent(node))
-           );
+    const bool nodeInvalid = ( 
+		 mHierarchyInterface->GetParent(node) && 
+		 (mHierarchyInterface->LastVisited(node) == mHierarchyInterface->GetFrameId()) && 
+		 !mHierarchyInterface->IsNodeVisible(mHierarchyInterface->GetParent(node))
+         );
+
+	/*if (nodeInvalid)
+		CullingLogManager::GetSingleton()->LogMessage("node invalid");
+	*/
+
+	return nodeInvalid;
 }
 //-----------------------------------------------------------------------
@@ -296,4 +352,7 @@
 		IssueQuery(*nit, false);
 
+	//for (int i = (int)nodes.size() - 1; i >= 0; -- i)
+	//	IssueQuery(nodes[i], false);
+
 	nodes.clear();
 }
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreSolidBoundingBox.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreSolidBoundingBox.cpp	(revision 2532)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreSolidBoundingBox.cpp	(revision 2556)
@@ -84,6 +84,6 @@
 void SolidBoundingBox::SetupBoundingBoxVertices(const AxisAlignedBox& aab) 
 {
-	const Vector3& min = aab.getMinimum();
-    const Vector3& max = aab.getMaximum();
+	const Vector3& minV = aab.getMinimum();
+    const Vector3& maxV = aab.getMaximum();
 
 	// fill the vertex buffer: 12 lines with 2 endpoints each make up a box
@@ -93,13 +93,13 @@
     float* pPos = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
 
-	*pPos++ = min.x; *pPos++ = max.y; *pPos++ = min.z; 
-	*pPos++ = max.x; *pPos++ = max.y; *pPos++ = min.z; 
-	*pPos++ = max.x; *pPos++ = min.y; *pPos++ = min.z; 
-	*pPos++ = min.x; *pPos++ = min.y; *pPos++ = min.z; 
+	pPos[0]  = minV.x; pPos[1]  = maxV.y; pPos[2]  = minV.z; 
+	pPos[3]  = maxV.x; pPos[4]  = maxV.y; pPos[5]  = minV.z; 
+	pPos[6]  = maxV.x; pPos[7]  = minV.y; pPos[8]  = minV.z; 
+	pPos[9]  = minV.x; pPos[10]  = minV.y; pPos[11] = minV.z; 
 		
-	*pPos++ = min.x; *pPos++ = max.y; *pPos++ = max.z; 
-	*pPos++ = max.x; *pPos++ = max.y; *pPos++ = max.z; 
-	*pPos++ = max.x; *pPos++ = min.y; *pPos++ = max.z; 
-	*pPos++ = min.x; *pPos++ = min.y; *pPos++ = max.z;
+	pPos[12] = minV.x; pPos[13] = maxV.y; pPos[14] = maxV.z; 
+	pPos[15] = maxV.x; pPos[16] = maxV.y; pPos[17] = maxV.z; 
+	pPos[18] = maxV.x; pPos[19] = minV.y; pPos[20] = maxV.z; 
+	pPos[21] = minV.x; pPos[22] = minV.y; pPos[23] = maxV.z;
 
     vbuf->unlock();
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformHierarchyInterface.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformHierarchyInterface.cpp	(revision 2555)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformHierarchyInterface.cpp	(revision 2556)
@@ -240,4 +240,5 @@
 	////////
 	//-- the actual query test
+
 	query->BeginQuery();
 
