this is my (unorganized, unoptimitzed and ugly i know) occlusion culling code. it works fine - except for some frames in which meshes that cover a large portion of the screen seem to flicker.

<vector> m_vpkVisibleGroups contains meshes that passed view frustum culling.
<vector> m_vpkVisibleNotOccludedGroups contains the meshes from the first array that passed occlusion culling.

Code :
	// generate query id's
	unsigned int uiCount = m_vpkVisibleGroups.size();
	unsigned int *uiQueryIds = new unsigned int[uiCount];
 
	glGenQueries( uiCount, &amp;uiQueryIds[0] );
 
	for( unsigned int i = 0; i < m_vpkVisibleGroups.size(); i++ )
	{
		// get group
		Group *pkGroup = m_vpkVisibleGroups[i];
 
		// begin query
		glBeginQuery( GL_SAMPLES_PASSED, uiQueryIds[i] );
 
		// render bounding box
		pkGroup->GetBoundingBox()->Render( false );
 
		// end query
		glEndQuery( GL_SAMPLES_PASSED );
	}
 
	unsigned int uiResult = 0;
 
	do
	{
		glGetQueryObjectuiv( uiQueryIds[uiCount-1], GL_QUERY_RESULT_AVAILABLE, &amp;uiResult );
	}
	while( !uiResult );
 
	m_vpkVisibleNotOccludedGroups.clear();
	for( unsigned int i = 0; i < uiCount; i++ )
	{
		// get result
		unsigned int uiResult;
		glGetQueryObjectuiv( uiQueryIds[i], GL_QUERY_RESULT, &amp;uiResult );
 
		if( uiResult )
		{
			m_vpkVisibleNotOccludedGroups.push_back( m_vpkVisibleGroups[i] );
		}
	}
 
	// delete query id's
	glDeleteQueries( uiCount, &amp;uiQueryIds[0] );
any idea what's wrong? glFlush() didn't help.