]> git.mxchange.org Git - simgear.git/commitdiff
Solve the endless loop problem for the DC-3 and prevent a potential segmentation...
authorehofman <ehofman>
Fri, 14 May 2004 19:46:12 +0000 (19:46 +0000)
committerehofman <ehofman>
Fri, 14 May 2004 19:46:12 +0000 (19:46 +0000)
simgear/scene/model/animation.cxx
simgear/scene/model/animation.hxx
simgear/scene/model/model.cxx

index 68cd908f888852dcc112fc9c3f91bbf886168d54..0e5e274ec0f9cb77cd1ea5ed51eabf84c273ed01 100644 (file)
@@ -441,21 +441,35 @@ SGTimedAnimation::SGTimedAnimation (SGPropertyNode_ptr props)
                                                           rNode->getDoubleValue( "max", 1.0 ) );
         }
     }
+}
+
+SGTimedAnimation::~SGTimedAnimation ()
+{
+}
+
+void
+SGTimedAnimation::init()
+{
     if ( !_use_personality ) {
-        for ( size_t i = 0; i < _branch_duration_specs.size(); i++ ) {
-            DurationSpec &sp = _branch_duration_specs[ i ];
-            double v = sp._min + sg_random() * ( sp._max - sp._min );
+        for ( size_t i = 0; i < getBranch()->getNumKids(); i++ ) {
+            double v;
+            if ( i < _branch_duration_specs.size() ) {
+                DurationSpec &sp = _branch_duration_specs[ i ];
+                v = sp._min + sg_random() * ( sp._max - sp._min );
+            } else {
+                v = _duration_sec;
+            }
             _branch_duration_sec.push_back( v );
             _total_duration_sec += v;
         }
+        // Sanity check : total duration shouldn't equal zero
+        if ( _total_duration_sec < 0.01 ) {
+            _total_duration_sec = 0.01;
+        }
     }
     ((ssgSelector *)getBranch())->selectStep(_step);
 }
 
-SGTimedAnimation::~SGTimedAnimation ()
-{
-}
-
 int
 SGTimedAnimation::update()
 {
@@ -472,6 +486,10 @@ SGTimedAnimation::update()
                     offset = v;
                 total += v;
             }
+            // Sanity check : total duration shouldn't equal zero
+            if ( total < 0.01 ) {
+                total = 0.01;
+            }
             offset *= sg_random();
             key->setDoubleValue( sim_time_sec - offset, this, LAST_TIME_SEC );
             key->setDoubleValue( total, this, TOTAL_DURATION_SEC );
index 95807afb599463fe81f9a0c78576b005c83c1341..0fcd229d655d2767f664d50dc20e39c1a4e1e1e8 100644 (file)
@@ -187,6 +187,7 @@ class SGTimedAnimation : public SGAnimation
 public:
     SGTimedAnimation (SGPropertyNode_ptr props);
     virtual ~SGTimedAnimation ();
+    virtual void init();
     virtual int update();
 private:
     bool _use_personality;
index 3d7cf5f3f8493ee3244905fde46a991cc959a19f..a9363596e79122cd6f6543ec2f8c7718d507f3a3 100644 (file)
@@ -192,10 +192,11 @@ sgMakeAnimation( ssgBranch * model,
           SG_LOG(SG_INPUT, SG_WARN, "Object " << name << " not found");
           delete animation;
           animation = 0;
+      } else {
+          ssgBranch * oldParent = object->getParent(0);
+          branch->addKid(object);
+          oldParent->removeKid(object);
       }
-      ssgBranch * oldParent = object->getParent(0);
-      branch->addKid(object);
-      oldParent->removeKid(object);
   }
 
   animation->init();