Skip to content

Commit

Permalink
ObjectIndex: fix a problem with the getObjectIDs method that caused i…
Browse files Browse the repository at this point in the history
…t to not work on non-Geometry Drawables (like LineDrawable), #2700
  • Loading branch information
gwaldron committed Feb 19, 2025
1 parent 160efb1 commit 4634806
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions src/osgEarth/ObjectIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,22 +274,39 @@ ObjectIndex::tagNode(osg::Node* node, ObjectID id) const
}
}

namespace
{
struct GetObjectIDs : public osg::Drawable::ConstAttributeFunctor
{
osg::Drawable::AttributeType _attribLocation = 0;
std::set<ObjectID>* _output = nullptr;

void apply(osg::Drawable::AttributeType type, unsigned size, const GLuint* data) override
{
if (type == _attribLocation)
{
for (int i = 0; i < size; ++i)
{
_output->insert(data[i]);
}
}
}
};
}

bool
ObjectIndex::getObjectIDs(const osg::Drawable* drawable, std::set<ObjectID>& output) const
{
if (!drawable) return false;

const osg::Geometry* geometry = drawable->asGeometry();
if (!geometry) return false;

const ObjectIDArray* oids = dynamic_cast<const ObjectIDArray*>(geometry->getVertexAttribArray(_attribLocation));
if ( !oids ) return false;
if (oids->empty()) return false;
const ObjectIDArray* oids = nullptr;

for (ObjectIDArray::const_iterator i = oids->begin(); i != oids->end(); ++i)
output.insert( *i );
GetObjectIDs getter;
getter._attribLocation = _attribLocation;
getter._output = &output;
drawable->accept(getter);

return true;
return !output.empty();
}

bool
Expand Down

0 comments on commit 4634806

Please sign in to comment.