Index: /OpenSceneGraph/trunk/src/osg/OcclusionQueryNode.cpp
===================================================================
--- /OpenSceneGraph/trunk/src/osg/OcclusionQueryNode.cpp (revision 9460)
+++ /OpenSceneGraph/trunk/src/osg/OcclusionQueryNode.cpp (revision 10933)
@@ -528,6 +528,4 @@
     _debugBB( false )
 {
-    setDataVariance( osg::Object::DYNAMIC );
-
     // OQN has two Geode member variables, one for doing the
     //   query and one for rendering the debug geometry.
@@ -562,8 +560,5 @@
         return true;
 
-    // In the future, we could hold a reference directly to the QueryDrawable
-    //   to avoid the dynamic_cast.
-    QueryGeometry* qg = dynamic_cast< QueryGeometry* >( _queryGeode->getDrawable( 0 ) );
-    if (qg == NULL)
+    if (_queryGeode->getDrawable( 0 ) == NULL)
     {
         osg::notify( osg::FATAL ) <<
@@ -572,4 +567,5 @@
         return true;
     }
+    QueryGeometry* qg = static_cast< QueryGeometry* >( _queryGeode->getDrawable( 0 ) );
 
     // If the distance to the bounding sphere shell is positive, retrieve
@@ -642,8 +638,8 @@
         (*v)[7] = osg::Vec3( bb._max.x(), bb._max.y(), bb._max.z() );
 
-        osg::Geometry* geom = dynamic_cast< osg::Geometry* >( nonConstThis->_queryGeode->getDrawable( 0 ) );
+        osg::Geometry* geom = static_cast< osg::Geometry* >( nonConstThis->_queryGeode->getDrawable( 0 ) );
         geom->setVertexArray( v.get() );
 
-        geom = dynamic_cast< osg::Geometry* >( nonConstThis->_debugGeode->getDrawable( 0 ) );
+        geom = static_cast< osg::Geometry* >( nonConstThis->_debugGeode->getDrawable( 0 ) );
         geom->setVertexArray( v.get() );
     }
@@ -799,8 +795,11 @@
 OcclusionQueryNode::releaseGLObjects( osg::State* state ) const
 {
-    // Query object discard and deletion is handled by QueryGeometry support class.
-    OcclusionQueryNode* nonConstThis = const_cast< OcclusionQueryNode* >( this );
-    QueryGeometry* qg = dynamic_cast< QueryGeometry* >( nonConstThis->_queryGeode->getDrawable( 0 ) );
-    qg->releaseGLObjects( state );
+    if(_queryGeode->getDrawable( 0 ) != NULL)
+    {
+        // Query object discard and deletion is handled by QueryGeometry support class.
+        OcclusionQueryNode* nonConstThis = const_cast< OcclusionQueryNode* >( this );
+        QueryGeometry* qg = static_cast< QueryGeometry* >( nonConstThis->_queryGeode->getDrawable( 0 ) );
+        qg->releaseGLObjects( state );
+    }
 }
 
