diff --git a/src/Cockpit/od_gauge.cxx b/src/Cockpit/od_gauge.cxx index 3bf03b6bd..e83d7fcfe 100644 --- a/src/Cockpit/od_gauge.cxx +++ b/src/Cockpit/od_gauge.cxx @@ -70,16 +70,16 @@ FGODGauge::~FGODGauge() * Used to remember the located groups that require modification */ typedef struct { - typedef osg::ref_ptr GroupPtr; - GroupPtr parent; - GroupPtr node; - int unit; + osg::ref_ptr parent; + osg::ref_ptr node; + unsigned int unit; }GroupListItem; /** * Replace a texture in the airplane model with the gauge texture. */ class ReplaceStaticTextureVisitor: + public osg::NodeVisitor { public: @@ -134,10 +134,10 @@ class ReplaceStaticTextureVisitor: virtual void apply(osg::Geode& node) { - simgear::EffectGeode* eg = dynamic_cast(&node); - if( !eg ) + simgear::EffectGeode* effectGeode = dynamic_cast(&node); + if( !effectGeode ) return; - simgear::Effect* eff = eg->getEffect(); + simgear::Effect* eff = effectGeode->getEffect(); if (!eff) return; osg::StateSet* ss = eff->getDefaultStateSet(); @@ -175,7 +175,7 @@ class ReplaceStaticTextureVisitor: return; } - for( size_t unit = 0; unit < ss->getNumTextureAttributeLists(); ++unit ) + for( unsigned int unit = 0; unit < ss->getNumTextureAttributeLists(); ++unit ) { osg::Texture2D* tex = dynamic_cast ( @@ -195,41 +195,34 @@ class ReplaceStaticTextureVisitor: /* * remember this group for modification once the scenegraph has been traversed */ - GroupListItem gli; - gli.node = eg; - gli.parent = parent; - gli.unit = unit; - groups_to_modify.push_back(gli); - return; + groups_to_modify.push_back({ parent, &node, unit }); + return; } } /* * this section of code used to be in the apply method above, however to work this requires modification of the scenegraph nodes * that are currently iterating, so instead the apply method will locate the groups to be modified and when finished then the * nodes can actually be modified safely. Initially found thanks to the debug RTL in MSVC2015 throwing an exception. + * should be called immediately after the visitor to ensure that the groups are still valid and that nothing else has modified these groups. */ void modify_groups() { - for (GroupList::iterator group_iterator = groups_to_modify.begin(); group_iterator != groups_to_modify.end(); group_iterator++) { - GroupPtr eg = group_iterator->node; - GroupPtr parent = group_iterator->parent; - int unit = group_iterator->unit; - - // insert a new group between the geode an it's parent which overrides + for (auto g : groups_to_modify) { + // insert a new group between the geode an it's parent which overrides // the texture GroupPtr group = new osg::Group; group->setName("canvas texture group"); - group->addChild(eg); - parent->removeChild(eg); - parent->addChild(group); + group->addChild(g.node); + g.parent->removeChild(g.node); + g.parent->addChild(group); if (_cull_callback) group->setCullCallback(_cull_callback); osg::StateSet* stateSet = group->getOrCreateStateSet(); - stateSet->setTextureAttribute(unit, _new_texture, + stateSet->setTextureAttribute(g.unit, _new_texture, osg::StateAttribute::OVERRIDE); - stateSet->setTextureMode(unit, GL_TEXTURE_2D, + stateSet->setTextureMode(g.unit, GL_TEXTURE_2D, osg::StateAttribute::ON); _placements.push_back(simgear::canvas::PlacementPtr( @@ -241,7 +234,7 @@ class ReplaceStaticTextureVisitor: SG_GL, SG_INFO, "Replaced texture '" << _tex_name << "'" - << " for object '" << parent->getName() << "'" + << " for object '" << g.parent->getName() << "'" << (!_parent_name.empty() ? " with parent '" + _parent_name + "'" : "") );