]> git.mxchange.org Git - simgear.git/commitdiff
Make SGModelPlacement safe on reinit
authorThorstenB <brehmt@gmail.com>
Tue, 11 Oct 2011 19:28:37 +0000 (21:28 +0200)
committerThorstenB <brehmt@gmail.com>
Tue, 11 Oct 2011 19:28:37 +0000 (21:28 +0200)
Remove old model When init is called multiple times (i.e. reinit).
Also allow explicit removal of submodel (= init(0) ).

simgear/scene/model/placement.cxx

index 852844921f5424ede40e8297cf8c54a5a74dd926..8d2ab9f2b1f7e38c2171bfb006153a8ba7af17e2 100644 (file)
@@ -25,6 +25,7 @@ SGModelPlacement::SGModelPlacement () :
     _selector(new osg::Switch),
     _transform(new osg::PositionAttitudeTransform)
 {
+    _selector->addChild(_transform.get());
 }
 
 SGModelPlacement::~SGModelPlacement ()
@@ -34,10 +35,11 @@ SGModelPlacement::~SGModelPlacement ()
 void
 SGModelPlacement::init( osg::Node * model )
 {
+  // remove previous model (in case of reinit)
+  _transform->removeChild(0,1);
   if (model != 0) {
       _transform->addChild(model);
   }
-  _selector->addChild(_transform.get());
   _selector->setValue(0, 1);
 }