]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/sky/cloudfield.cxx
Work around apparent OSG 3.2.0 normal binding bug.
[simgear.git] / simgear / scene / sky / cloudfield.cxx
index f3abdc12966aa87bd16629cb638f1201822ee162..45ae15f83c4b4cd9feb71f7d376b28e5578b0d0d 100644 (file)
@@ -130,6 +130,11 @@ bool SGCloudField::reposition( const SGVec3f& p, const SGVec3f& up, double lon,
             ++itr) {
               
              osg::ref_ptr<osg::PositionAttitudeTransform> pat = itr->second;
+            
+             if (pat == 0) {
+                continue;
+             }
+             
              osg::Vec3f currpos = field_transform->getPosition() + fta * pat->getPosition();
                                       
              // Determine the vector from the new position to the cloud in cloud-space.
@@ -178,7 +183,7 @@ SGCloudField::SGCloudField() :
 }
     
 SGCloudField::~SGCloudField() {
-        }
+}
 
 
 void SGCloudField::clear(void) {
@@ -208,7 +213,7 @@ void SGCloudField::applyVisAndLoDRange(void)
             
 bool SGCloudField::addCloud(float lon, float lat, float alt, int index, osg::ref_ptr<EffectGeode> geode) {
   return addCloud(lon, lat, alt, 0.0f, 0.0f, index, geode);
-        }
+}
 
 bool SGCloudField::addCloud(float lon, float lat, float alt, float x, float y, int index, osg::ref_ptr<EffectGeode> geode) {
     // If this cloud index already exists, don't replace it.
@@ -220,11 +225,16 @@ bool SGCloudField::addCloud(float lon, float lat, float alt, float x, float y, i
     addCloudToTree(transform, lon, lat, alt, x, y);
     cloud_hash[index] = transform;
     return true;
-    }
-    
+}
+
 // Remove a give cloud from inside the tree, without removing it from the cloud hash
 void SGCloudField::removeCloudFromTree(osg::ref_ptr<osg::PositionAttitudeTransform> transform)
 {
+    if (transform == 0)
+    {
+        // Ooops!
+        return;
+    }
     osg::ref_ptr<osg::Group> lodnode = transform->getParent(0);
     lodnode->removeChild(transform);
     cloudcount--;
@@ -236,8 +246,8 @@ void SGCloudField::removeCloudFromTree(osg::ref_ptr<osg::PositionAttitudeTransfo
         lodnode1->removeChild(lodnode);
         lodcount--;
 
-        if (lodnode1->getNumChildren() == 0) {        
-          impostornode->removeChild(lodnode1);        
+        if (lodnode1->getNumChildren() == 0) {
+          impostornode->removeChild(lodnode1);
           placed_root->removeChild(impostornode);
           impostorcount--;
         }
@@ -362,7 +372,7 @@ void SGCloudField::addCloudToTree(osg::ref_ptr<osg::PositionAttitudeTransform> t
         
 bool SGCloudField::deleteCloud(int identifier) {
     osg::ref_ptr<osg::PositionAttitudeTransform> transform = cloud_hash[identifier];
-    if (transform == NULL) return false;
+    if (transform == 0) return false;
         
     removeCloudFromTree(transform);
     cloud_hash.erase(identifier);
@@ -385,7 +395,7 @@ bool SGCloudField::repositionCloud(int identifier, float lon, float lat, float a
     }
 
 bool SGCloudField::isDefined3D(void) {
-    return (cloud_hash.size() > 0);
+    return (! cloud_hash.empty());
 }
 
 SGCloudField::CloudFog::CloudFog() {