Added handling of null dynamic_cast.

This commit is contained in:
Robert Osfield 2016-06-30 09:54:13 +01:00
parent 576a265095
commit a469d60ed2

View File

@ -61,21 +61,24 @@ void TriangleStripVisitor::mergeTrianglesStrip(osg::Geometry& geometry)
else if (ps->getType() == osg::PrimitiveSet::DrawArraysPrimitiveType) { else if (ps->getType() == osg::PrimitiveSet::DrawArraysPrimitiveType) {
// trip strip can generate drawarray of 5 elements we want to merge them too // trip strip can generate drawarray of 5 elements we want to merge them too
osg::DrawArrays* da = dynamic_cast<osg::DrawArrays*> (ps); osg::DrawArrays* da = dynamic_cast<osg::DrawArrays*> (ps);
// if connection needed insert degenerate triangles if (da)
if (ndw->getNumIndices() != 0 && ndw->back() != da->getFirst()) { {
// duplicate last vertex // if connection needed insert degenerate triangles
ndw->addElement(ndw->back()); if (ndw->getNumIndices() != 0 && ndw->back() != da->getFirst()) {
// insert first vertex of next strip // duplicate last vertex
ndw->addElement(da->getFirst()); ndw->addElement(ndw->back());
} // insert first vertex of next strip
ndw->addElement(da->getFirst());
}
if (ndw->getNumIndices() % 2 != 0 ) { if (ndw->getNumIndices() % 2 != 0 ) {
// add a dummy vertex to reverse the strip // add a dummy vertex to reverse the strip
ndw->addElement(da->getFirst()); ndw->addElement(da->getFirst());
} }
for (unsigned int j = 0; j < da->getNumIndices(); j++) { for (unsigned int j = 0; j < da->getNumIndices(); j++) {
ndw->addElement(da->getFirst() + j); ndw->addElement(da->getFirst() + j);
}
} }
} }
} }