Fixed indentation, replaced dynamic_cast<> with static_cast<> as we know the type and add check against null pointers

This commit is contained in:
Robert Osfield
2016-06-17 09:48:21 +01:00
parent 09df93813d
commit 951c41cf9e

View File

@@ -436,8 +436,9 @@ void Tessellator::handleNewVertices(osg::Geometry& geom,VertexPtrToIndexMap &ver
{
if (!_newVertexList.empty())
{
osg::Vec3Array* vertices = dynamic_cast<osg::Vec3Array*>(geom.getVertexArray());
if (!vertices) return;
osg::Vec3Array* normals = NULL;
if (osg::getBinding(geom.getNormalArray())==osg::Array::BIND_PER_VERTEX)
{
@@ -583,29 +584,34 @@ void CALLBACK Tessellator::errorCallback(GLenum errorCode, void* userData)
void Tessellator::reduceArray(osg::Array * cold, const unsigned int nnu)
{ // shrinks size of array to N
if (cold && cold->getNumElements()>nnu) {
if (cold && cold->getNumElements()>nnu)
{
osg::Vec2Array* v2arr = NULL;
osg::Vec3Array* v3arr = NULL;
osg::Vec4Array* v4arr = NULL;
switch (cold->getType()) {
case osg::Array::Vec2ArrayType: {
v2arr = dynamic_cast<osg::Vec2Array*>(cold);
switch (cold->getType())
{
case osg::Array::Vec2ArrayType:
{
v2arr = static_cast<osg::Vec2Array*>(cold);
osg::Vec2Array::iterator itr=v2arr->begin()+nnu;
(*v2arr).erase(itr, v2arr->end());
}
break;
case osg::Array::Vec3ArrayType: {
v3arr = dynamic_cast<osg::Vec3Array*>(cold);
}
break;
case osg::Array::Vec3ArrayType:
{
v3arr = static_cast<osg::Vec3Array*>(cold);
osg::Vec3Array::iterator itr=v3arr->begin()+nnu;
(*v3arr).erase(itr, v3arr->end());
}
break;
case osg::Array::Vec4ArrayType: {
v4arr = dynamic_cast<osg::Vec4Array*>(cold);
}
break;
case osg::Array::Vec4ArrayType:
{
v4arr = static_cast<osg::Vec4Array*>(cold);
osg::Vec4Array::iterator itr=v4arr->begin()+nnu;
(*v4arr).erase(itr, v4arr->end());
}
break;
}
break;
default: // should also handle:ArrayType' ByteArrayType' ShortArrayType' IntArrayType'
// `UShortArrayType' `UIntArrayType' `Vec4ubArrayType' `FloatArrayType'
break;
@@ -618,6 +624,9 @@ void Tessellator::collectTessellation(osg::Geometry &geom, unsigned int /*origin
if (geom.containsDeprecatedData()) geom.fixDeprecatedData();
osg::Vec3Array* vertices = dynamic_cast<osg::Vec3Array*>(geom.getVertexArray());
if (!vertices) return;
VertexPtrToIndexMap vertexPtrToIndexMap;
// populate the VertexPtrToIndexMap.