From 6fd972fa429fc2d8eac77984e7d0f967d3d85ae0 Mon Sep 17 00:00:00 2001 From: Marc Helbling Date: Tue, 5 Jul 2016 16:32:00 +0200 Subject: [PATCH] Fixes gles coverity defects --- src/osgPlugins/gles/AABBonBoneVisitor | 285 ++++++++++-------- src/osgPlugins/gles/AnimationCleanerVisitor | 22 +- src/osgPlugins/gles/GeometryArray | 23 +- src/osgPlugins/gles/GeometryInspector | 5 +- src/osgPlugins/gles/GeometrySplitterVisitor | 3 +- src/osgPlugins/gles/LimitMorphTargetCount | 4 +- src/osgPlugins/gles/Line | 2 + src/osgPlugins/gles/OpenGLESGeometryOptimizer | 1 + src/osgPlugins/gles/PrimitiveIndexors | 2 + src/osgPlugins/gles/RigAnimationVisitor | 2 +- src/osgPlugins/gles/RigAttributesVisitor | 4 +- src/osgPlugins/gles/SmoothNormalVisitor | 13 +- src/osgPlugins/gles/StatLogger | 2 + src/osgPlugins/gles/SubGeometry | 15 +- src/osgPlugins/gles/TriangleMeshGraph | 12 +- src/osgPlugins/gles/glesUtil | 2 + 16 files changed, 219 insertions(+), 178 deletions(-) diff --git a/src/osgPlugins/gles/AABBonBoneVisitor b/src/osgPlugins/gles/AABBonBoneVisitor index dcb9f01aa..b2857c7af 100644 --- a/src/osgPlugins/gles/AABBonBoneVisitor +++ b/src/osgPlugins/gles/AABBonBoneVisitor @@ -1,4 +1,4 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) Cedric Pinson +/* -*-c++-*- OpenSceneGraph - Copyright (C) Sketchfab * * This application is open source and may be redistributed and/or modified * freely and without restriction, both in commercial and non commercial @@ -36,90 +36,6 @@ public: typedef std::vector RigGeometryList; - osg::Geometry* createBox(const osg::BoundingBox &bb, const osg::Matrix &transform, - float ratio=1.0, osg::Vec4 color=osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f)) { - osg::Geometry *cube = new osg::Geometry; - - osg::Vec3 center = bb.center(); - double halfLenghtX = (bb._max.x() - bb._min.x()) * 0.50; - double halfLenghtY = (bb._max.y() - bb._min.y()) * 0.50; - double halfLenghtZ = (bb._max.z() - bb._min.z()) * 0.50; - - halfLenghtX *= ratio; - halfLenghtY *= ratio; - halfLenghtZ *= ratio; - - osg::Vec3Array *cubeVertices = new osg::Vec3Array; - cubeVertices->push_back(osg::Vec3(center.x() - halfLenghtX, center.y() + halfLenghtY, center.z() + halfLenghtZ) * transform); - cubeVertices->push_back(osg::Vec3(center.x() - halfLenghtX, center.y() + halfLenghtY, center.z() - halfLenghtZ) * transform); - cubeVertices->push_back(osg::Vec3(center.x() - halfLenghtX, center.y() - halfLenghtY, center.z() - halfLenghtZ) * transform); - cubeVertices->push_back(osg::Vec3(center.x() - halfLenghtX, center.y() - halfLenghtY, center.z() + halfLenghtZ) * transform); - - cubeVertices->push_back(osg::Vec3(center.x() + halfLenghtX, center.y() + halfLenghtY, center.z() + halfLenghtZ) * transform); - cubeVertices->push_back(osg::Vec3(center.x() + halfLenghtX, center.y() + halfLenghtY, center.z() - halfLenghtZ) * transform); - cubeVertices->push_back(osg::Vec3(center.x() + halfLenghtX, center.y() - halfLenghtY, center.z() - halfLenghtZ) * transform); - cubeVertices->push_back(osg::Vec3(center.x() + halfLenghtX, center.y() - halfLenghtY, center.z() + halfLenghtZ) * transform); - - cube->setVertexArray(cubeVertices); - - osg::DrawElementsUInt* up = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0); - up->push_back(4); - up->push_back(5); - up->push_back(1); - up->push_back(0); - cube->addPrimitiveSet(up); - - osg::DrawElementsUInt* down = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0); - down->push_back(2); - down->push_back(6); - down->push_back(7); - down->push_back(3); - cube->addPrimitiveSet(down); - - osg::DrawElementsUInt* left = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0); - left->push_back(2); - left->push_back(3); - left->push_back(0); - left->push_back(1); - cube->addPrimitiveSet(left); - - osg::DrawElementsUInt* right = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0); - right->push_back(7); - right->push_back(6); - right->push_back(5); - right->push_back(4); - cube->addPrimitiveSet(right); - - osg::DrawElementsUInt* front = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0); - front->push_back(3); - front->push_back(7); - front->push_back(4); - front->push_back(0); - cube->addPrimitiveSet(front); - - osg::DrawElementsUInt* back = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0); - back->push_back(6); - back->push_back(2); - back->push_back(1); - back->push_back(5); - cube->addPrimitiveSet(back); - - osg::Vec4Array* colors = new osg::Vec4Array; - colors->push_back(color); - colors->push_back(color); - colors->push_back(color); - colors->push_back(color); - colors->push_back(color); - colors->push_back(color); - colors->push_back(color); - colors->push_back(color); - - cube->setColorArray(colors); - cube->setColorBinding(osg::Geometry::BIND_PER_VERTEX); - - return cube; - } - ComputeAABBOnBoneVisitor(bool createGeometry): osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), _root(0), @@ -149,59 +65,28 @@ public: _rigGeometries.push_back(&rig); } - void serializeBoundingBox(const osg::BoundingBox &bb, const osg::Matrix &transform, osgAnimation::Bone &b, float ratio = 1.0) { - osg::Vec3 center = bb.center(); - double halfLenghtX = (bb._max.x() - bb._min.x()) * 0.50; - double halfLenghtY = (bb._max.y() - bb._min.y()) * 0.50; - double halfLenghtZ = (bb._max.z() - bb._min.z()) * 0.50; - - halfLenghtX *= ratio; - halfLenghtY *= ratio; - halfLenghtZ *= ratio; - - osg::BoundingBox serializedBB; - - serializedBB.expandBy(osg::Vec3(center.x() - halfLenghtX, center.y() + halfLenghtY, center.z() + halfLenghtZ) * transform); - serializedBB.expandBy(osg::Vec3(center.x() - halfLenghtX, center.y() + halfLenghtY, center.z() - halfLenghtZ) * transform); - serializedBB.expandBy(osg::Vec3(center.x() - halfLenghtX, center.y() - halfLenghtY, center.z() - halfLenghtZ) * transform); - serializedBB.expandBy(osg::Vec3(center.x() - halfLenghtX, center.y() - halfLenghtY, center.z() + halfLenghtZ) * transform); - serializedBB.expandBy(osg::Vec3(center.x() + halfLenghtX, center.y() + halfLenghtY, center.z() + halfLenghtZ) * transform); - serializedBB.expandBy(osg::Vec3(center.x() + halfLenghtX, center.y() + halfLenghtY, center.z() - halfLenghtZ) * transform); - serializedBB.expandBy(osg::Vec3(center.x() + halfLenghtX, center.y() - halfLenghtY, center.z() - halfLenghtZ) * transform); - serializedBB.expandBy(osg::Vec3(center.x() + halfLenghtX, center.y() - halfLenghtY, center.z() + halfLenghtZ) * transform); - - b.setUserValue("AABBonBone_min", serializedBB._min); - b.setUserValue("AABBonBone_max", serializedBB._max); - } - void computeBoundingBoxOnBones() { //Perform Updates - - //Update Bones - osgUtil::UpdateVisitor up; - _root->accept(up); - - //Update rigGeometries - for (unsigned int i = 0, size = _rigGeometries.size(); i < size; i++) { - osgAnimation::RigGeometry * rig = _rigGeometries.at(i); - osg::Drawable::UpdateCallback * up = dynamic_cast(rig->getUpdateCallback()); - if(up) up->update(0, rig); - } + updateBones(); + updateRigGeometries(); //We have our T pose, we can compute an AABB for each bone for (BoneList::iterator bone = _bones.begin(); bone != _bones.end(); ++ bone) { osg::BoundingBox bb; //For each geometry - for (RigGeometryList::iterator rigGeometry = _rigGeometries.begin(); rigGeometry != _rigGeometries.end(); ++ rigGeometry) { - osg::Matrix mtxLocalToSkl = (*rigGeometry)->getWorldMatrices(_root).at(0); + for (RigGeometryList::iterator iterator = _rigGeometries.begin(); iterator != _rigGeometries.end(); ++ iterator) { + osgAnimation::RigGeometry* rigGeometry = *iterator; + if(!rigGeometry) continue; + + osg::Matrix mtxLocalToSkl = rigGeometry->getWorldMatrices(_root).at(0); //For each Vertex influence - osgAnimation::VertexInfluenceMap * infMap = (*rigGeometry)->getInfluenceMap(); + osgAnimation::VertexInfluenceMap * infMap = rigGeometry->getInfluenceMap(); osgAnimation::VertexInfluenceMap::iterator itMap = infMap->find((*bone)->getName()); if(itMap == infMap->end()) continue; osgAnimation::VertexInfluence vxtInf = (*itMap).second; - osg::Vec3Array *vertices = dynamic_cast((*rigGeometry)->getVertexArray()); + osg::Vec3Array *vertices = dynamic_cast(rigGeometry->getVertexArray()); //Expand the boundingBox with each vertex for(unsigned int j = 0; j < vxtInf.size(); j++) { @@ -230,14 +115,154 @@ public: } //Clear geometries - for (RigGeometryList::iterator rigGeometry = _rigGeometries.begin(); rigGeometry != _rigGeometries.end(); ++ rigGeometry) { - (*rigGeometry)->copyFrom(*(*rigGeometry)->getSourceGeometry()); - (*rigGeometry)->setRigTransformImplementation(0); + for (RigGeometryList::iterator iterator = _rigGeometries.begin(); iterator != _rigGeometries.end(); ++ iterator) { + osgAnimation::RigGeometry* rigGeometry = *iterator; + if(rigGeometry) { + rigGeometry->copyFrom(*rigGeometry->getSourceGeometry()); + rigGeometry->setRigTransformImplementation(0); + } } } - std::vector _bones; - std::vector _rigGeometries; +protected: + osg::Geometry* createBox(const osg::BoundingBox &bb, const osg::Matrix &transform, + float ratio=1.0, osg::Vec4 color=osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f)) { + osg::Geometry *cube = new osg::Geometry; + + osg::Vec3 center = bb.center(); + double halfLenghtX = (bb._max.x() - bb._min.x()) * 0.50; + double halfLenghtY = (bb._max.y() - bb._min.y()) * 0.50; + double halfLenghtZ = (bb._max.z() - bb._min.z()) * 0.50; + + halfLenghtX *= ratio; + halfLenghtY *= ratio; + halfLenghtZ *= ratio; + + osg::Vec3Array *cubeVertices = new osg::Vec3Array; + cubeVertices->push_back(osg::Vec3(center.x() - halfLenghtX, center.y() + halfLenghtY, center.z() + halfLenghtZ) * transform); + cubeVertices->push_back(osg::Vec3(center.x() - halfLenghtX, center.y() + halfLenghtY, center.z() - halfLenghtZ) * transform); + cubeVertices->push_back(osg::Vec3(center.x() - halfLenghtX, center.y() - halfLenghtY, center.z() - halfLenghtZ) * transform); + cubeVertices->push_back(osg::Vec3(center.x() - halfLenghtX, center.y() - halfLenghtY, center.z() + halfLenghtZ) * transform); + + cubeVertices->push_back(osg::Vec3(center.x() + halfLenghtX, center.y() + halfLenghtY, center.z() + halfLenghtZ) * transform); + cubeVertices->push_back(osg::Vec3(center.x() + halfLenghtX, center.y() + halfLenghtY, center.z() - halfLenghtZ) * transform); + cubeVertices->push_back(osg::Vec3(center.x() + halfLenghtX, center.y() - halfLenghtY, center.z() - halfLenghtZ) * transform); + cubeVertices->push_back(osg::Vec3(center.x() + halfLenghtX, center.y() - halfLenghtY, center.z() + halfLenghtZ) * transform); + + cube->setVertexArray(cubeVertices); + + { + osg::DrawElementsUInt* up = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0); + up->push_back(4); + up->push_back(5); + up->push_back(1); + up->push_back(0); + cube->addPrimitiveSet(up); + } + + { + osg::DrawElementsUInt* down = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0); + down->push_back(2); + down->push_back(6); + down->push_back(7); + down->push_back(3); + cube->addPrimitiveSet(down); + } + + { + osg::DrawElementsUInt* left = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0); + left->push_back(2); + left->push_back(3); + left->push_back(0); + left->push_back(1); + cube->addPrimitiveSet(left); + } + + { + osg::DrawElementsUInt* right = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0); + right->push_back(7); + right->push_back(6); + right->push_back(5); + right->push_back(4); + cube->addPrimitiveSet(right); + } + + { + osg::DrawElementsUInt* front = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0); + front->push_back(3); + front->push_back(7); + front->push_back(4); + front->push_back(0); + cube->addPrimitiveSet(front); + } + + { + osg::DrawElementsUInt* back = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0); + back->push_back(6); + back->push_back(2); + back->push_back(1); + back->push_back(5); + cube->addPrimitiveSet(back); + } + + osg::Vec4Array* colors = new osg::Vec4Array; + colors->push_back(color); + colors->push_back(color); + colors->push_back(color); + colors->push_back(color); + colors->push_back(color); + colors->push_back(color); + colors->push_back(color); + colors->push_back(color); + + cube->setColorArray(colors); + cube->setColorBinding(osg::Geometry::BIND_PER_VERTEX); + + return cube; + } + + void serializeBoundingBox(const osg::BoundingBox &bb, const osg::Matrix &transform, osgAnimation::Bone &b, float ratio = 1.0) { + osg::Vec3 center = bb.center(); + double halfLenghtX = (bb._max.x() - bb._min.x()) * 0.50; + double halfLenghtY = (bb._max.y() - bb._min.y()) * 0.50; + double halfLenghtZ = (bb._max.z() - bb._min.z()) * 0.50; + + halfLenghtX *= ratio; + halfLenghtY *= ratio; + halfLenghtZ *= ratio; + + osg::BoundingBox serializedBB; + + serializedBB.expandBy(osg::Vec3(center.x() - halfLenghtX, center.y() + halfLenghtY, center.z() + halfLenghtZ) * transform); + serializedBB.expandBy(osg::Vec3(center.x() - halfLenghtX, center.y() + halfLenghtY, center.z() - halfLenghtZ) * transform); + serializedBB.expandBy(osg::Vec3(center.x() - halfLenghtX, center.y() - halfLenghtY, center.z() - halfLenghtZ) * transform); + serializedBB.expandBy(osg::Vec3(center.x() - halfLenghtX, center.y() - halfLenghtY, center.z() + halfLenghtZ) * transform); + serializedBB.expandBy(osg::Vec3(center.x() + halfLenghtX, center.y() + halfLenghtY, center.z() + halfLenghtZ) * transform); + serializedBB.expandBy(osg::Vec3(center.x() + halfLenghtX, center.y() + halfLenghtY, center.z() - halfLenghtZ) * transform); + serializedBB.expandBy(osg::Vec3(center.x() + halfLenghtX, center.y() - halfLenghtY, center.z() - halfLenghtZ) * transform); + serializedBB.expandBy(osg::Vec3(center.x() + halfLenghtX, center.y() - halfLenghtY, center.z() + halfLenghtZ) * transform); + + b.setUserValue("AABBonBone_min", serializedBB._min); + b.setUserValue("AABBonBone_max", serializedBB._max); + } + + void updateBones() { + osgUtil::UpdateVisitor update; + _root->accept(update); + } + + void updateRigGeometries() { + for (unsigned int i = 0, size = _rigGeometries.size(); i < size; i++) { + osgAnimation::RigGeometry * rig = _rigGeometries.at(i); + osg::Drawable::UpdateCallback * callback = dynamic_cast(rig->getUpdateCallback()); + if(callback) { + callback->update(0, rig); + } + } + } + + BoneList _bones; + RigGeometryList _rigGeometries; osgAnimation::Skeleton *_root; bool _createGeometry; }; diff --git a/src/osgPlugins/gles/AnimationCleanerVisitor b/src/osgPlugins/gles/AnimationCleanerVisitor index 38e217621..9d91e6a07 100644 --- a/src/osgPlugins/gles/AnimationCleanerVisitor +++ b/src/osgPlugins/gles/AnimationCleanerVisitor @@ -65,7 +65,7 @@ public: geometry(false) {} - void apply(osg::Geometry& object) { + void apply(osg::Geometry& /*object*/) { geometry = true; } @@ -266,18 +266,16 @@ public: // Replace rig geometries by static geometries if: // * empty or inexistant vertex influence map // * no *strictly* positive influence coefficient - - RigGeometryList::iterator rigGeometry = _rigGeometries.begin(); - while(rigGeometry != _rigGeometries.end()) { - if(rigGeometry->valid()) { - if(!hasPositiveWeights((*rigGeometry)->getSourceGeometry())) { - OSG_WARN << "Monitor: animation.invalid_riggeometry" << std::endl; - replaceRigGeometryBySource(*(rigGeometry->get())); - _rigGeometries.erase(rigGeometry); - continue; // skip iterator increment - } + for(RigGeometryList::iterator iterator = _rigGeometries.begin() ; iterator != _rigGeometries.end() ; ) { + osg::ref_ptr rigGeometry = *iterator; + if(rigGeometry.valid() && !hasPositiveWeights(rigGeometry->getSourceGeometry())) { + OSG_WARN << "Monitor: animation.invalid_riggeometry" << std::endl; + replaceRigGeometryBySource(*rigGeometry.get()); + _rigGeometries.erase(iterator); + } + else { + ++ iterator; } - ++ rigGeometry; } } diff --git a/src/osgPlugins/gles/GeometryArray b/src/osgPlugins/gles/GeometryArray index eaf97e227..0cc6d60a4 100644 --- a/src/osgPlugins/gles/GeometryArray +++ b/src/osgPlugins/gles/GeometryArray @@ -1,4 +1,5 @@ -/* -*-c++-*- */ +/* -*-c++-*- OpenSceneGraph - Copyright (C) Cedric Pinson */ + #ifndef GEOMETRY_ARRAY_UTILS_H #define GEOMETRY_ARRAY_UTILS_H @@ -98,7 +99,7 @@ struct GeometryArrayList { template bool arrayAppendElement(osg::Array* src, unsigned int index, osg::Array* dst) { T* array = dynamic_cast(src); - if (array) { + if (array && dst) { T* arrayDst = dynamic_cast(dst); arrayDst->push_back((*array)[index]); return true; @@ -140,15 +141,6 @@ struct GeometryArrayList { if (arrayAppendElement(src, index, dst)) return; - if (arrayAppendElement(src, index, dst)) - return; - - if (arrayAppendElement(src, index, dst)) - return; - - if (arrayAppendElement(src, index, dst)) - return; - if (arrayAppendElement(src, index, dst)) return; @@ -266,15 +258,6 @@ struct GeometryArrayList { if (arraySetNumElements(array, numElements)) return; - if (arraySetNumElements(array, numElements)) - return; - - if (arraySetNumElements(array, numElements)) - return; - - if (arraySetNumElements(array, numElements)) - return; - if (arraySetNumElements(array, numElements)) return; diff --git a/src/osgPlugins/gles/GeometryInspector b/src/osgPlugins/gles/GeometryInspector index 2e8f822c4..beea59194 100644 --- a/src/osgPlugins/gles/GeometryInspector +++ b/src/osgPlugins/gles/GeometryInspector @@ -1,3 +1,5 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) Sketchfab */ + #ifndef GEOMETRY_INSPECTOR #define GEOMETRY_INSPECTOR @@ -17,7 +19,8 @@ class GeometryInspector : public GeometryUniqueVisitor { public: - void process(osg::Geometry& geometry) {} + void process(osg::Geometry& /*geometry*/) {} + void process(osgAnimation::RigGeometry& rigGeometry) { osgAnimation::MorphGeometry* morph = dynamic_cast(rigGeometry.getSourceGeometry()); if(morph) { diff --git a/src/osgPlugins/gles/GeometrySplitterVisitor b/src/osgPlugins/gles/GeometrySplitterVisitor index e238ec836..5de2118ca 100644 --- a/src/osgPlugins/gles/GeometrySplitterVisitor +++ b/src/osgPlugins/gles/GeometrySplitterVisitor @@ -133,7 +133,8 @@ public: setTriangleCluster(graph, cache.back(), cluster, clusters, cluster_vertices, remaining_triangles); while(remaining_triangles && cluster_vertices.size() < _maxAllowedIndex) { - unsigned int candidate; + unsigned int candidate = std::numeric_limits::max(); + for(IndexCache::const_reverse_iterator cached = cache.rbegin() ; cached != cache.rend() ; ++ cached) { candidate = findCandidate(graph.triangleNeighbors(*cached), clusters); if(candidate != std::numeric_limits::max()) break; diff --git a/src/osgPlugins/gles/LimitMorphTargetCount b/src/osgPlugins/gles/LimitMorphTargetCount index 6e0a10da4..38e25656a 100644 --- a/src/osgPlugins/gles/LimitMorphTargetCount +++ b/src/osgPlugins/gles/LimitMorphTargetCount @@ -1,8 +1,8 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) Sketchfab */ + #ifndef LIMIT_MORPH_TARGET_COUNT_VISITOR #define LIMIT_MORPH_TARGET_COUNT_VISITOR -/* -*-c++-*- OpenSceneGraph - Copyright (C) Sketchfab */ - #include "GeometryUniqueVisitor" diff --git a/src/osgPlugins/gles/Line b/src/osgPlugins/gles/Line index b27fd4b3a..9079f67a0 100644 --- a/src/osgPlugins/gles/Line +++ b/src/osgPlugins/gles/Line @@ -1,3 +1,5 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) Sketchfab */ + #ifndef GLES_LINE #define GLES_LINE diff --git a/src/osgPlugins/gles/OpenGLESGeometryOptimizer b/src/osgPlugins/gles/OpenGLESGeometryOptimizer index 9eb36c74b..751a9f2bd 100644 --- a/src/osgPlugins/gles/OpenGLESGeometryOptimizer +++ b/src/osgPlugins/gles/OpenGLESGeometryOptimizer @@ -49,6 +49,7 @@ public: _disableMergeTriStrip(false), _disablePreTransform(false), _disableAnimation(false), + _disableAnimationCleaning(false), _enableAABBonBone(false), _triStripCacheSize(16), _triStripMinSize(2), diff --git a/src/osgPlugins/gles/PrimitiveIndexors b/src/osgPlugins/gles/PrimitiveIndexors index 7e83e6d6b..5791b0e02 100644 --- a/src/osgPlugins/gles/PrimitiveIndexors +++ b/src/osgPlugins/gles/PrimitiveIndexors @@ -1,3 +1,5 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) Sketchfab */ + #ifndef PRIMITIVE_OPERATORS_H #define PRIMITIVE_OPERATORS_H diff --git a/src/osgPlugins/gles/RigAnimationVisitor b/src/osgPlugins/gles/RigAnimationVisitor index f069f5b43..3d1e1feb5 100644 --- a/src/osgPlugins/gles/RigAnimationVisitor +++ b/src/osgPlugins/gles/RigAnimationVisitor @@ -1,4 +1,4 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) Cedric Pinson +/* -*-c++-*- OpenSceneGraph - Copyright (C) Sketchfab * * This application is open source and may be redistributed and/or modified * freely and without restriction, both in commercial and non commercial diff --git a/src/osgPlugins/gles/RigAttributesVisitor b/src/osgPlugins/gles/RigAttributesVisitor index 6674fb9d1..13cd47fe6 100644 --- a/src/osgPlugins/gles/RigAttributesVisitor +++ b/src/osgPlugins/gles/RigAttributesVisitor @@ -1,3 +1,5 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) Sketchfab */ + #ifndef RIG_ATTRIBUTES_VISITOR #define RIG_ATTRIBUTES_VISITOR @@ -31,7 +33,7 @@ public: } } - void process(osg::Geometry& geometry) { + void process(osg::Geometry& /*geometry*/) { return; } diff --git a/src/osgPlugins/gles/SmoothNormalVisitor b/src/osgPlugins/gles/SmoothNormalVisitor index 2f72275a4..62ba9ae75 100644 --- a/src/osgPlugins/gles/SmoothNormalVisitor +++ b/src/osgPlugins/gles/SmoothNormalVisitor @@ -1,3 +1,5 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) Sketchfab */ + #include #include #include @@ -197,7 +199,16 @@ protected: bool flipped = false; osg::Vec3Array* normals = dynamic_cast(_geometry.getNormalArray()); - for(unsigned int index = 0 ; index < _geometry.getVertexArray()->getNumElements() ; ++ index) { + osg::Vec3Array* positions = dynamic_cast(_geometry.getVertexArray()); + + if(!positions || !normals || normals->getNumElements() != positions->getNumElements()) { + OSG_WARN << std::endl + << "Warning: [smoothVertexNormals] [[normals]] Geometry '" << _geometry.getName() + << "' has invalid positions/normals"; + return; + } + + for(unsigned int index = 0 ; index < positions->getNumElements() ; ++ index) { std::vector oneRing = _graph->vertexOneRing(_graph->unify(index), _creaseAngle); osg::Vec3f smoothedNormal(0.f, 0.f, 0.f); diff --git a/src/osgPlugins/gles/StatLogger b/src/osgPlugins/gles/StatLogger index 047483157..a69f8006d 100644 --- a/src/osgPlugins/gles/StatLogger +++ b/src/osgPlugins/gles/StatLogger @@ -1,3 +1,5 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) Sketchfab */ + #ifndef STAT_LOGGER #define STAT_LOGGER diff --git a/src/osgPlugins/gles/SubGeometry b/src/osgPlugins/gles/SubGeometry index b9c81a7f7..41b1d0129 100644 --- a/src/osgPlugins/gles/SubGeometry +++ b/src/osgPlugins/gles/SubGeometry @@ -1,3 +1,5 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) Sketchfab */ + #ifndef SUB_GEOMETRY #define SUB_GEOMETRY @@ -49,11 +51,14 @@ public: if(const osgAnimation::MorphGeometry* morphSource = dynamic_cast(&source)) { osgAnimation::MorphGeometry* morph = dynamic_cast(_geometry.get()); const osgAnimation::MorphGeometry::MorphTargetList& morphTargetList = morphSource->getMorphTargetList(); - for(osgAnimation::MorphGeometry::MorphTargetList::const_iterator targetSource = morphTargetList.begin() ; - targetSource != morphTargetList.end() ; ++ targetSource) { - osg::Geometry* target = new osg::Geometry; - addSourceBuffers(target, *targetSource->getGeometry()); - morph->addMorphTarget(target, targetSource->getWeight()); + + osgAnimation::MorphGeometry::MorphTargetList::const_iterator targetSource; + for(targetSource = morphTargetList.begin() ; targetSource != morphTargetList.end() ; ++ targetSource) { + if(targetSource->getGeometry()) { + osg::Geometry* target = new osg::Geometry; + addSourceBuffers(target, *targetSource->getGeometry()); + morph->addMorphTarget(target, targetSource->getWeight()); + } } } diff --git a/src/osgPlugins/gles/TriangleMeshGraph b/src/osgPlugins/gles/TriangleMeshGraph index 052bce56c..1c48e3832 100644 --- a/src/osgPlugins/gles/TriangleMeshGraph +++ b/src/osgPlugins/gles/TriangleMeshGraph @@ -1,3 +1,5 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) Sketchfab */ + #ifndef MESH_GRAPH #define MESH_GRAPH @@ -171,10 +173,12 @@ public: _positions(dynamic_cast(geometry.getVertexArray())), _comparePosition(comparePosition) { - unsigned int nbVertex = _positions->getNumElements(); - _unique.resize(nbVertex, std::numeric_limits::max()); - _vertexTriangles.resize(nbVertex, IndexVector()); - build(); + if(_positions) { + unsigned int nbVertex = _positions->getNumElements(); + _unique.resize(nbVertex, std::numeric_limits::max()); + _vertexTriangles.resize(nbVertex, IndexVector()); + build(); + } } VertexIterator begin() const { diff --git a/src/osgPlugins/gles/glesUtil b/src/osgPlugins/gles/glesUtil index 1e3b0b388..f9db652bd 100644 --- a/src/osgPlugins/gles/glesUtil +++ b/src/osgPlugins/gles/glesUtil @@ -1,3 +1,5 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) Sketchfab */ + #ifndef GLES_UTIL #define GLES_UTIL