diff --git a/code/BlenderCustomData.cpp b/code/BlenderCustomData.cpp index 682186618..6561eaf22 100644 --- a/code/BlenderCustomData.cpp +++ b/code/BlenderCustomData.cpp @@ -28,7 +28,11 @@ namespace Assimp { #define IMPL_STRUCT_READ(ty) \ bool read##ty(ElemBase *v, const size_t cnt, const FileDatabase &db) { \ - return read(db.dna[#ty], dynamic_cast(v), cnt, db); \ + ty *ptr = dynamic_cast(v); \ + if (nullptr == ptr) { \ + return false; \ + } \ + return read(db.dna[#ty], ptr, cnt, db); \ } #define IMPL_STRUCT_CREATE(ty) \ diff --git a/code/ColladaExporter.cpp b/code/ColladaExporter.cpp index 0d5bdd46d..9d66741eb 100644 --- a/code/ColladaExporter.cpp +++ b/code/ColladaExporter.cpp @@ -1500,24 +1500,18 @@ void ColladaExporter::WriteNode( const aiScene* pScene, aiNode* pNode) // otherwise it is a normal node (NODE) const char * node_type; bool is_joint, is_skeleton_root = false; - if (NULL == findBone(pScene, pNode->mName.C_Str())) { + if (nullptr == findBone(pScene, pNode->mName.C_Str())) { node_type = "NODE"; is_joint = false; } else { node_type = "JOINT"; is_joint = true; - if(!pNode->mParent || NULL == findBone(pScene, pNode->mParent->mName.C_Str())) + if (!pNode->mParent || nullptr == findBone(pScene, pNode->mParent->mName.C_Str())) { is_skeleton_root = true; + } } const std::string node_name_escaped = XMLEscape(pNode->mName.data); - /* // customized, Note! the id field is crucial for inter-xml look up, it cannot be replaced with sid ?! - mOutput << startstr - << " Node(const std::string& n, const More... more) - : name(n) - { AddProperties(more...); } + : name(n) + , properties() + , children() + , force_has_children(false) { + AddProperties(more...); + } public: // functions to add properties or children // add a single property to the node diff --git a/code/FBXExporter.cpp b/code/FBXExporter.cpp index 037520641..ce00deee3 100644 --- a/code/FBXExporter.cpp +++ b/code/FBXExporter.cpp @@ -131,13 +131,15 @@ namespace Assimp { } // end of namespace Assimp -FBXExporter::FBXExporter ( - const aiScene* pScene, - const ExportProperties* pProperties -) - : mScene(pScene) - , mProperties(pProperties) -{ +FBXExporter::FBXExporter ( const aiScene* pScene, const ExportProperties* pProperties ) +: binary(false) +, mScene(pScene) +, mProperties(pProperties) +, outfile() +, connections() +, mesh_uids() +, material_uids() +, node_uids() { // will probably need to determine UIDs, connections, etc here. // basically anything that needs to be known // before we start writing sections to the stream. @@ -2444,7 +2446,6 @@ void FBXExporter::WriteAnimationCurve( // TODO: keyattr flags and data (STUB for now) n.AddChild("KeyAttrFlags", std::vector{0}); n.AddChild("KeyAttrDataFloat", std::vector{0,0,0,0}); - ai_assert(static_cast(times.size()) <= std::numeric_limits::max()); n.AddChild( "KeyAttrRefCount", std::vector{static_cast(times.size())} diff --git a/code/SceneCombiner.cpp b/code/SceneCombiner.cpp index 883447372..2271194ca 100644 --- a/code/SceneCombiner.cpp +++ b/code/SceneCombiner.cpp @@ -738,7 +738,11 @@ void SceneCombiner::MergeBones(aiMesh* out,std::vector::const_iterator // And copy the final weights - adjust the vertex IDs by the // face index offset of the corresponding mesh. - for (std::vector< BoneSrcIndex >::const_iterator wmit = (*boneIt).pSrcBones.begin(); wmit != wend; ++wmit) { + for (std::vector< BoneSrcIndex >::const_iterator wmit = (*boneIt).pSrcBones.begin(); wmit != (*boneIt).pSrcBones.end(); ++wmit) { + if (wmit == wend) { + break; + } + aiBone* pip = (*wmit).first; for (unsigned int mp = 0; mp < pip->mNumWeights;++mp,++avw) { const aiVertexWeight& vfi = pip->mWeights[mp]; diff --git a/code/XGLLoader.cpp b/code/XGLLoader.cpp index 0706ffd55..2dfd51284 100644 --- a/code/XGLLoader.cpp +++ b/code/XGLLoader.cpp @@ -370,7 +370,7 @@ aiLight* XGLImporter::ReadDirectionalLight() // ------------------------------------------------------------------------------------------------ aiNode* XGLImporter::ReadObject(TempScope& scope, bool skipFirst, const char* closetag) { - std::unique_ptr nd(new aiNode()); + aiNode *nd = new aiNode; std::vector children; std::vector meshes; @@ -453,11 +453,11 @@ aiNode* XGLImporter::ReadObject(TempScope& scope, bool skipFirst, const char* cl nd->mChildren = new aiNode*[nd->mNumChildren](); for(unsigned int i = 0; i < nd->mNumChildren; ++i) { nd->mChildren[i] = children[i]; - children[i]->mParent = nd.get(); + children[i]->mParent = nd; } } - return nd.release(); + return nd; } // ------------------------------------------------------------------------------------------------ @@ -731,11 +731,10 @@ unsigned int XGLImporter::ResolveMaterialRef(TempScope& scope) } // ------------------------------------------------------------------------------------------------ -void XGLImporter::ReadMaterial(TempScope& scope) -{ +void XGLImporter::ReadMaterial(TempScope& scope) { const unsigned int mat_id = ReadIDAttr(); - std::unique_ptr mat(new aiMaterial()); + aiMaterial *mat(new aiMaterial ); while (ReadElementUpToClosing("mat")) { const std::string& s = GetElementName(); if (s == "amb") { @@ -764,11 +763,10 @@ void XGLImporter::ReadMaterial(TempScope& scope) } } - scope.materials[mat_id] = mat.get(); - scope.materials_linear.push_back(mat.release()); + scope.materials[mat_id] = mat; + scope.materials_linear.push_back(mat); } - // ---------------------------------------------------------------------------------------------- void XGLImporter::ReadFaceVertex(const TempMesh& t, TempFace& out) { diff --git a/code/glTF2Asset.h b/code/glTF2Asset.h index 92be82f3b..6672dd7a9 100644 --- a/code/glTF2Asset.h +++ b/code/glTF2Asset.h @@ -656,7 +656,11 @@ namespace glTF2 } ortographic; } cameraProperties; - Camera() {} + Camera() + : type(Perspective) + , cameraProperties() { + // empty + } void Read(Value& obj, Asset& r); }; diff --git a/code/glTF2AssetWriter.inl b/code/glTF2AssetWriter.inl index 50d855aaa..75726fd08 100644 --- a/code/glTF2AssetWriter.inl +++ b/code/glTF2AssetWriter.inl @@ -744,6 +744,9 @@ namespace glTF2 { if (!(dict = FindArray(*container, d.mDictId))) { container->AddMember(StringRef(d.mDictId), Value().SetArray().Move(), mDoc.GetAllocator()); dict = FindArray(*container, d.mDictId); + if (nullptr == dict) { + return; + } } for (size_t i = 0; i < d.mObjs.size(); ++i) { diff --git a/code/glTF2Exporter.cpp b/code/glTF2Exporter.cpp index 40db27264..2c6bab2e0 100644 --- a/code/glTF2Exporter.cpp +++ b/code/glTF2Exporter.cpp @@ -643,11 +643,12 @@ void ExportSkin(Asset& mAsset, const aiMesh* aimesh, Ref& meshRef, Ref buf = vertexJointAccessor->bufferView->buffer; uint8_t* arrys = new uint8_t[bytesLen]; unsigned int i = 0; + uint8_t* data = new uint8_t[s_bytesPerComp]; for ( unsigned int j = 0; j <= bytesLen; j += bytesPerComp ){ size_t len_p = offset + j; float f_value = *(float *)&buf->GetPointer()[len_p]; unsigned short c = static_cast(f_value); - uint8_t* data = new uint8_t[s_bytesPerComp]; + ::memset(data, 0, s_bytesPerComp * sizeof(uint8_t)); data = (uint8_t*)&c; memcpy(&arrys[i*s_bytesPerComp], data, s_bytesPerComp); ++i; @@ -657,6 +658,8 @@ void ExportSkin(Asset& mAsset, const aiMesh* aimesh, Ref& meshRef, RefbufferView->byteLength = s_bytesLen; p.attributes.joint.push_back( vertexJointAccessor ); + delete[] arrys; + delete[] data; } Ref vertexWeightAccessor = ExportData(mAsset, skinRef->id, bufferRef, aimesh->mNumVertices, vertexWeightData, AttribType::VEC4, AttribType::VEC4, ComponentType_FLOAT); diff --git a/code/glTF2Importer.cpp b/code/glTF2Importer.cpp index 107281a33..20c28f498 100755 --- a/code/glTF2Importer.cpp +++ b/code/glTF2Importer.cpp @@ -763,6 +763,12 @@ static void BuildVertexWeightMapping(Mesh::Primitive& primitive, std::vectorExtractData(indices16); } + // + if (nullptr == indices8 && nullptr == indices16) { + // Something went completely wrong! + ai_assert(false); + return; + } for (int i = 0; i < num_vertices; ++i) { for (int j = 0; j < 4; ++j) { diff --git a/test/unit/utPLYImportExport.cpp b/test/unit/utPLYImportExport.cpp index 5aabe0805..540996b21 100644 --- a/test/unit/utPLYImportExport.cpp +++ b/test/unit/utPLYImportExport.cpp @@ -56,6 +56,9 @@ public: const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/PLY/cube.ply", aiProcess_ValidateDataStructure); EXPECT_EQ( 1u, scene->mNumMeshes ); EXPECT_NE( nullptr, scene->mMeshes[0] ); + if (nullptr == scene->mMeshes[0]) { + return false; + } EXPECT_EQ( 8u, scene->mMeshes[0]->mNumVertices ); EXPECT_EQ( 6u, scene->mMeshes[0]->mNumFaces ); diff --git a/test/unit/utglTF2ImportExport.cpp b/test/unit/utglTF2ImportExport.cpp index 264580aad..08fa9d989 100644 --- a/test/unit/utglTF2ImportExport.cpp +++ b/test/unit/utglTF2ImportExport.cpp @@ -356,11 +356,12 @@ std::vector ReadFile(const char* name) { } ::fseek(p, 0, SEEK_END); - const auto size = ::ftell(p); + const size_t size = ::ftell(p); ::fseek(p, 0, SEEK_SET); ret.resize(size); - ::fread(&ret[0], 1, size, p); + const size_t readSize = ::fread(&ret[0], 1, size, p); + EXPECT_EQ(readSize, size); ::fclose(p); return ret;