Forráskód Böngészése

glTF importers: Avoid strncpy truncating away the ' \0' character (#5931)

* Fixing building errors from job https://github.com/assimp/assimp/actions/runs/12403918024/job/34628244451?pr=5928

* Adding some asserts for future mantainability, although a bit paranoic maybe

---------

Co-authored-by: Kim Kulling <[email protected]>
David Campos Rodríguez 8 hónapja
szülő
commit
016be03c3d

+ 8 - 11
code/AssetLib/glTF/glTFImporter.cpp

@@ -44,7 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include "AssetLib/glTF/glTFImporter.h"
 #include "AssetLib/glTF/glTFAsset.h"
 #if !defined(ASSIMP_BUILD_NO_EXPORT)
-#include "AssetLib/glTF/glTFAssetWriter.h"
+#   include "AssetLib/glTF/glTFAssetWriter.h"
 #endif
 #include "PostProcessing/MakeVerboseFormat.h"
 
@@ -67,7 +67,11 @@ static constexpr aiImporterDesc desc = {
     "",
     "",
     "",
-    aiImporterFlags_SupportTextFlavour | aiImporterFlags_SupportBinaryFlavour | aiImporterFlags_SupportCompressedFlavour | aiImporterFlags_LimitedSupport | aiImporterFlags_Experimental,
+    aiImporterFlags_SupportTextFlavour | 
+        aiImporterFlags_SupportBinaryFlavour | 
+        aiImporterFlags_SupportCompressedFlavour | 
+        aiImporterFlags_LimitedSupport | 
+        aiImporterFlags_Experimental,
     0,
     0,
     0,
@@ -129,11 +133,8 @@ void glTFImporter::ImportMaterials(glTF::Asset &r) {
         aiMaterial *aimat = mScene->mMaterials[i] = new aiMaterial();
 
         Material &mat = r.materials[i];
-
-        /*if (!mat.name.empty())*/ {
-            aiString str(mat.id /*mat.name*/);
-            aimat->AddProperty(&str, AI_MATKEY_NAME);
-        }
+        aiString str(mat.id);
+        aimat->AddProperty(&str, AI_MATKEY_NAME);
 
         SetMaterialColorProperty(embeddedTexIdxs, r, mat.ambient, aimat, aiTextureType_AMBIENT, AI_MATKEY_COLOR_AMBIENT);
         SetMaterialColorProperty(embeddedTexIdxs, r, mat.diffuse, aimat, aiTextureType_DIFFUSE, AI_MATKEY_COLOR_DIFFUSE);
@@ -616,10 +617,6 @@ void glTFImporter::ImportNodes(glTF::Asset &r) {
         }
         mScene->mRootNode = root;
     }
-
-    //if (!mScene->mRootNode) {
-    //  mScene->mRootNode = new aiNode("EMPTY");
-    //}
 }
 
 void glTFImporter::ImportEmbeddedTextures(glTF::Asset &r) {

+ 5 - 3
code/AssetLib/glTF2/glTF2Importer.cpp

@@ -46,7 +46,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include "PostProcessing/MakeVerboseFormat.h"
 
 #if !defined(ASSIMP_BUILD_NO_EXPORT)
-#include "AssetLib/glTF2/glTF2AssetWriter.h"
+#   include "AssetLib/glTF2/glTF2AssetWriter.h"
 #endif
 
 #include <assimp/CreateAnimMesh.h>
@@ -1055,7 +1055,8 @@ static void BuildVertexWeightMapping(Mesh::Primitive &primitive, std::vector<std
             attr.joint[j]->ExtractData(indices16[j], vertexRemappingTablePtr);
         }
     }
-    //
+    
+    // No indices are an invalid usecase
     if (nullptr == indices8 && nullptr == indices16) {
         // Something went completely wrong!
         ai_assert(false);
@@ -1456,7 +1457,8 @@ std::unordered_map<unsigned int, AnimationSamplers> GatherSamplers(Animation &an
         }
 
         if (animsampler.input->count > animsampler.output->count) {
-            ASSIMP_LOG_WARN("Animation ", anim.name, ": Number of keyframes in sampler input ", animsampler.input->count, " exceeds number of keyframes in sampler output ", animsampler.output->count);
+            ASSIMP_LOG_WARN("Animation ", anim.name, ": Number of keyframes in sampler input ", animsampler.input->count,
+                            " exceeds number of keyframes in sampler output ", animsampler.output->count);
             continue;
         }