From be2672586774066449a6895f58a655987de707e4 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 30 Jun 2016 09:59:27 +0100 Subject: [PATCH] Added handling of null dynamic_cast --- src/osgPlugins/gles/GeometryArray | 5 ++-- src/osgPlugins/osgjs/WriteVisitor.cpp | 42 ++++++++++++++++++--------- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/osgPlugins/gles/GeometryArray b/src/osgPlugins/gles/GeometryArray index 6665ca8d5..549b7417b 100644 --- a/src/osgPlugins/gles/GeometryArray +++ b/src/osgPlugins/gles/GeometryArray @@ -83,8 +83,9 @@ struct GeometryArrayList { template bool arrayAppendElement(osg::Array* src, unsigned int index, osg::Array* dst) { T* array= dynamic_cast(src); - if (array) { - T* arrayDst = dynamic_cast(dst); + T* arrayDst = dynamic_cast(dst); + if (array && arrayDst) + { arrayDst->push_back((*array)[index]); return true; } diff --git a/src/osgPlugins/osgjs/WriteVisitor.cpp b/src/osgPlugins/osgjs/WriteVisitor.cpp index 44ca75108..13916efa1 100644 --- a/src/osgPlugins/osgjs/WriteVisitor.cpp +++ b/src/osgPlugins/osgjs/WriteVisitor.cpp @@ -450,31 +450,45 @@ JSONObject* WriteVisitor::createJSONGeometry(osg::Geometry* geom) if (primitive->getType() == osg::PrimitiveSet::DrawArraysPrimitiveType) { osg::DrawArrays* da = dynamic_cast((primitive)); - primitives->getArray().push_back(obj); - if (da->getMode() == GL_QUADS) { - obj->getMaps()["DrawElementsUShort"] = createJSONDrawElements(da, geom); - } else { - obj->getMaps()["DrawArrays"] = createJSONDrawArray(da, geom); + if (da) + { + primitives->getArray().push_back(obj); + if (da->getMode() == GL_QUADS) { + obj->getMaps()["DrawElementsUShort"] = createJSONDrawElements(da, geom); + } else { + obj->getMaps()["DrawArrays"] = createJSONDrawArray(da, geom); + } } } else if (primitive->getType() == osg::PrimitiveSet::DrawElementsUIntPrimitiveType) { osg::DrawElementsUInt* da = dynamic_cast((primitive)); - primitives->getArray().push_back(obj); - obj->getMaps()["DrawElementsUInt"] = createJSONDrawElementsUInt(da, geom); + if (da) + { + primitives->getArray().push_back(obj); + obj->getMaps()["DrawElementsUInt"] = createJSONDrawElementsUInt(da, geom); + } } else if (primitive->getType() == osg::PrimitiveSet::DrawElementsUShortPrimitiveType) { osg::DrawElementsUShort* da = dynamic_cast((primitive)); - primitives->getArray().push_back(obj); - obj->getMaps()["DrawElementsUShort"] = createJSONDrawElementsUShort(da, geom); - + if (da) + { + primitives->getArray().push_back(obj); + obj->getMaps()["DrawElementsUShort"] = createJSONDrawElementsUShort(da, geom); + } } else if (primitive->getType() == osg::PrimitiveSet::DrawElementsUBytePrimitiveType) { osg::DrawElementsUByte* da = dynamic_cast((primitive)); - primitives->getArray().push_back(obj); - obj->getMaps()["DrawElementsUByte"] = createJSONDrawElementsUByte(da, geom); + if (da) + { + primitives->getArray().push_back(obj); + obj->getMaps()["DrawElementsUByte"] = createJSONDrawElementsUByte(da, geom); + } } else if (primitive->getType() == osg::PrimitiveSet::DrawArrayLengthsPrimitiveType) { osg::DrawArrayLengths* dal = dynamic_cast((primitive)); - primitives->getArray().push_back(obj); - obj->getMaps()["DrawArrayLengths"] = createJSONDrawArrayLengths(dal, geom); + if (dal) + { + primitives->getArray().push_back(obj); + obj->getMaps()["DrawArrayLengths"] = createJSONDrawArrayLengths(dal, geom); + } } else { osg::notify(osg::WARN) << "Primitive Type " << geom->getPrimitiveSetList()[i]->getType() << " not supported, skipping" << std::endl; }