Pārlūkot izejas kodu

closes https://github.com/assimp/assimp/issues/3165: fix gcc build.

kimkulling 5 gadi atpakaļ
vecāks
revīzija
d40a3026db

+ 12 - 2
code/AssetLib/STL/STLLoader.cpp

@@ -370,13 +370,23 @@ void STLImporter::LoadASCIIFile(aiNode *root) {
             pMesh->mNumFaces = static_cast<unsigned int>(positionBuffer.size() / 3);
             pMesh->mNumVertices = static_cast<unsigned int>(positionBuffer.size());
             pMesh->mVertices = new aiVector3D[pMesh->mNumVertices];
-            memcpy(pMesh->mVertices, &positionBuffer[0].x, pMesh->mNumVertices * sizeof(aiVector3D));
+            for (size_t i=0; i<pMesh->mNumVertices; ++i ) {
+                pMesh->mVertices[i].x = positionBuffer[i].x;
+                pMesh->mVertices[i].y = positionBuffer[i].y;                
+                pMesh->mVertices[i].z = positionBuffer[i].z;
+            }
+            //memcpy(pMesh->mVertices, &positionBuffer[0].x, pMesh->mNumVertices * sizeof(aiVector3D));
             positionBuffer.clear();
         }
         // also only process normalBuffer when filled, else exception when accessing with index operator
         if (!normalBuffer.empty()) {
             pMesh->mNormals = new aiVector3D[pMesh->mNumVertices];
-            memcpy(pMesh->mNormals, &normalBuffer[0].x, pMesh->mNumVertices * sizeof(aiVector3D));
+            for (size_t i=0; i<pMesh->mNumVertices; ++i ) {
+                pMesh->mNormals[i].x = normalBuffer[i].x;
+                pMesh->mNormals[i].y = normalBuffer[i].y;                
+                pMesh->mNormals[i].z = normalBuffer[i].z;
+            }
+//            memcpy(pMesh->mNormals, &normalBuffer[0].x, pMesh->mNumVertices * sizeof(aiVector3D));
             normalBuffer.clear();
         }
 

+ 3 - 2
code/AssetLib/glTF/glTFAsset.h

@@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
 
 Copyright (c) 2006-2020, assimp team
 
-
 All rights reserved.
 
 Redistribution and use of this software in source and binary forms,
@@ -62,10 +61,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <stdexcept>
 
 #define RAPIDJSON_HAS_STDSTRING 1
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wclass-memaccess"
 #include <rapidjson/rapidjson.h>
 #include <rapidjson/document.h>
 #include <rapidjson/error/en.h>
-
+#pragma GCC diagnostic pop
 #ifdef ASSIMP_API
 #   include <memory>
 #   include <assimp/DefaultIOSystem.h>

+ 3 - 1
code/AssetLib/glTF2/glTF2Asset.h

@@ -64,10 +64,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <vector>
 
 #define RAPIDJSON_HAS_STDSTRING 1
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wclass-memaccess"
 #include <rapidjson/document.h>
 #include <rapidjson/error/en.h>
 #include <rapidjson/rapidjson.h>
-
+#pragma GCC diagnostic pop
 #ifdef ASSIMP_API
 #include <assimp/ByteSwapper.h>
 #include <assimp/DefaultIOSystem.h>

+ 4 - 1
code/Common/SceneCombiner.cpp

@@ -978,7 +978,10 @@ void GetArrayCopy(Type*& dest, ai_uint num ) {
     Type* old = dest;
 
     dest = new Type[num];
-    ::memcpy(dest, old, sizeof(Type) * num);
+    for ( size_t i=0; i<num; ++i ) {
+    	dest[i] = old[i];
+    }
+//    ::memcpy(dest, old, sizeof(Type) * num);
 }
 
 // ------------------------------------------------------------------------------------------------

+ 4 - 8
code/Common/SpatialSort.cpp

@@ -210,20 +210,16 @@ BinFloat ToBinary(const ai_real &pValue) {
     // See http://en.wikipedia.org/wiki/Signed_number_representations.
 
     // Two's complement?
-    bool DefaultValue = ((-42 == (~42 + 1)) && (binValue & 0x80000000));
-    bool OneComplement = ((-42 == ~42) && (binValue & 0x80000000));
-    bool SignedMagnitude = ((-42 == (42 | (-0))) && (binValue & 0x80000000));
+    const bool DefaultValue = ((-42 == (~42 + 1)) && (binValue & 0x80000000));
+    const bool OneComplement = ((-42 == ~42) && (binValue & 0x80000000));
 
     if (DefaultValue)
         return BinFloat(1 << (CHAR_BIT * sizeof(BinFloat) - 1)) - binValue;
     // One's complement?
     else if (OneComplement)
         return BinFloat(-0) - binValue;
-    // Sign-magnitude?
-    else if (SignedMagnitude) // -0 = 1000... binary
-        return binValue;
-    else
-        return binValue;
+    // Sign-magnitude? -0 = 1000... binary
+    return binValue;
 }
 
 } // namespace

+ 6 - 2
test/unit/utFindInvalidData.cpp

@@ -106,8 +106,12 @@ void utFindInvalidDataProcess::TearDown() {
 
 // ------------------------------------------------------------------------------------------------
 TEST_F(utFindInvalidDataProcess, testStepNegativeResult) {
-    ::memset(mMesh->mNormals, 0, mMesh->mNumVertices * sizeof(aiVector3D));
-    ::memset(mMesh->mBitangents, 0, mMesh->mNumVertices * sizeof(aiVector3D));
+    for ( size_t i=0; i<mMesh->mNumVertices; ++i ) {
+        mMesh->mNormals[i].x = mMesh->mNormals[i].y = mMesh->mNormals[i].z =0;
+        mMesh->mBitangents[i].x = mMesh->mBitangents[i].y = mMesh->mBitangents[i].z = 0;
+    }
+    //::memset(mMesh->mNormals, 0, mMesh->mNumVertices * sizeof(aiVector3D));
+    //::memset(mMesh->mBitangents, 0, mMesh->mNumVertices * sizeof(aiVector3D));
 
     mMesh->mTextureCoords[2][455] = aiVector3D(std::numeric_limits<float>::quiet_NaN());