From 5ede8c12ba68cf1a0cda6e6d25c76d21a14612e8 Mon Sep 17 00:00:00 2001 From: ThorstenB Date: Tue, 11 Oct 2011 21:28:37 +0200 Subject: [PATCH] Make SGModelPlacement safe on reinit 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 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/simgear/scene/model/placement.cxx b/simgear/scene/model/placement.cxx index 85284492..8d2ab9f2 100644 --- a/simgear/scene/model/placement.cxx +++ b/simgear/scene/model/placement.cxx @@ -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); } -- 2.39.5