Fixed Coverity Scane reported issue.

This commit is contained in:
Robert Osfield
2017-11-01 11:35:05 +00:00
parent c242ad4497
commit fb175eed14
2 changed files with 25 additions and 8 deletions

View File

@@ -436,7 +436,7 @@ void ReaderWriter3DS::ReaderObject::addDrawableFromFace(osg::Geode * geode, Face
// Transforms points by matrix if 'matrix' is not NULL
// Creates a Geode and Geometry (as parent,child) and adds the Geode to 'parent' parameter iff 'parent' is non-NULL
// Returns ptr to the Geode
osg::Node* ReaderWriter3DS::ReaderObject::processMesh(StateSetMap& drawStateMap,osg::Group* parent,Lib3dsMesh* mesh, const osg::Matrix * matrix)
osg::Node* ReaderWriter3DS::ReaderObject::processMesh(StateSetMap& drawStateMap, osg::Group* parent, Lib3dsMesh* mesh, const osg::Matrix * matrix)
{
typedef std::vector<FaceList> MaterialFaceMap;
MaterialFaceMap materialFaceMap;
@@ -605,13 +605,17 @@ osg::Node* ReaderWriter3DS::ReaderObject::processNode(StateSetMap& drawStateMap,
// if noMatrixTransforms is not set, we create a transform node for the mesh's matrix
osg::Group* meshTransform=NULL;
if ((noMatrixTransforms==false) && meshAppliedMatPtr) { // we are allowed to have, and need another matrixtransform
if ((noMatrixTransforms==false) && meshAppliedMatPtr)
{
// we are allowed to have, and need another matrixtransform
meshTransform=new osg::MatrixTransform(meshMat);
meshAppliedMatPtr=NULL; // since meshTransform applies it
meshTransform->setName("3DSMeshMatrix");
if (group) group->addChild(meshTransform);
} else {
}
else
{
meshTransform=group; // don't need the meshTransform node - note group can be NULL
}
@@ -619,18 +623,21 @@ osg::Node* ReaderWriter3DS::ReaderObject::processNode(StateSetMap& drawStateMap,
{
// add our geometry to group (where our children already are)
// creates geometry under modifier node
processMesh(drawStateMap,meshTransform,mesh,meshAppliedMatPtr);
processMesh(drawStateMap, meshTransform, mesh, meshAppliedMatPtr);
return group;
}
else
{
// didn't use group for children, return a ptr directly to the Geode for this mesh
// there is no group node but may have a meshTransform node to hold the meshes matrix
if (meshTransform) {
processMesh(drawStateMap,meshTransform,mesh,meshAppliedMatPtr);
if (meshTransform)
{
processMesh(drawStateMap, meshTransform, mesh, meshAppliedMatPtr);
return meshTransform;
} else { // no group or meshTransform nodes - create a new Geode and return that
return processMesh(drawStateMap,NULL,mesh,meshAppliedMatPtr);
}
else
{ // no group or meshTransform nodes - create a new Geode and return that
return processMesh(drawStateMap, NULL, mesh, meshAppliedMatPtr);
}
}

View File

@@ -170,7 +170,17 @@ lib3ds_mesh_calculate_vertex_normals(Lib3dsMesh *mesh, float (*normals)[3]) {
}
fl = (Lib3dsFaces**)calloc(sizeof(Lib3dsFaces*), mesh->nvertices);
if (!fl)
{
return;
}
fa = (Lib3dsFaces*)malloc(sizeof(Lib3dsFaces) * 3 * mesh->nfaces);
if (!fa)
{
free(fl);
return;
}
for (i = 0; i < mesh->nfaces; ++i) {
for (j = 0; j < 3; ++j) {