From d40a3026dbacb24e1a1eab65ce0ea2b31dc8b2fd Mon Sep 17 00:00:00 2001 From: kimkulling Date: Thu, 28 May 2020 21:02:13 +0200 Subject: [PATCH 1/9] closes https://github.com/assimp/assimp/issues/3165: fix gcc build. --- code/AssetLib/STL/STLLoader.cpp | 14 ++++++++++++-- code/AssetLib/glTF/glTFAsset.h | 5 +++-- code/AssetLib/glTF2/glTF2Asset.h | 4 +++- code/Common/SceneCombiner.cpp | 5 ++++- code/Common/SpatialSort.cpp | 12 ++++-------- test/unit/utFindInvalidData.cpp | 8 ++++++-- 6 files changed, 32 insertions(+), 16 deletions(-) diff --git a/code/AssetLib/STL/STLLoader.cpp b/code/AssetLib/STL/STLLoader.cpp index 702f4fe5d..7d7fdb7c9 100644 --- a/code/AssetLib/STL/STLLoader.cpp +++ b/code/AssetLib/STL/STLLoader.cpp @@ -370,13 +370,23 @@ void STLImporter::LoadASCIIFile(aiNode *root) { pMesh->mNumFaces = static_cast(positionBuffer.size() / 3); pMesh->mNumVertices = static_cast(positionBuffer.size()); pMesh->mVertices = new aiVector3D[pMesh->mNumVertices]; - memcpy(pMesh->mVertices, &positionBuffer[0].x, pMesh->mNumVertices * sizeof(aiVector3D)); + for (size_t i=0; imNumVertices; ++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; imNumVertices; ++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(); } diff --git a/code/AssetLib/glTF/glTFAsset.h b/code/AssetLib/glTF/glTFAsset.h index 4c7aaa908..56cf18527 100644 --- a/code/AssetLib/glTF/glTFAsset.h +++ b/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 #define RAPIDJSON_HAS_STDSTRING 1 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wclass-memaccess" #include #include #include - +#pragma GCC diagnostic pop #ifdef ASSIMP_API # include # include diff --git a/code/AssetLib/glTF2/glTF2Asset.h b/code/AssetLib/glTF2/glTF2Asset.h index bfd4e4342..ed5f4318a 100644 --- a/code/AssetLib/glTF2/glTF2Asset.h +++ b/code/AssetLib/glTF2/glTF2Asset.h @@ -64,10 +64,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #define RAPIDJSON_HAS_STDSTRING 1 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wclass-memaccess" #include #include #include - +#pragma GCC diagnostic pop #ifdef ASSIMP_API #include #include diff --git a/code/Common/SceneCombiner.cpp b/code/Common/SceneCombiner.cpp index 4d2a411f2..2aa855989 100644 --- a/code/Common/SceneCombiner.cpp +++ b/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; imNormals, 0, mMesh->mNumVertices * sizeof(aiVector3D)); - ::memset(mMesh->mBitangents, 0, mMesh->mNumVertices * sizeof(aiVector3D)); + for ( size_t i=0; imNumVertices; ++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::quiet_NaN()); From 5c7bed01f1133956d63419220f918577e49dbc03 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 9 Jun 2020 10:06:50 +0200 Subject: [PATCH 2/9] remove dead code. --- code/AssetLib/STL/STLLoader.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/code/AssetLib/STL/STLLoader.cpp b/code/AssetLib/STL/STLLoader.cpp index 7d7fdb7c9..00cfe4b4d 100644 --- a/code/AssetLib/STL/STLLoader.cpp +++ b/code/AssetLib/STL/STLLoader.cpp @@ -5,8 +5,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, @@ -101,11 +99,13 @@ static bool IsAsciiSTL(const char *buffer, unsigned int fileSize) { const char *bufferEnd = buffer + fileSize; - if (!SkipSpaces(&buffer)) + if (!SkipSpaces(&buffer)) { return false; + } - if (buffer + 5 >= bufferEnd) + if (buffer + 5 >= bufferEnd) { return false; + } bool isASCII(strncmp(buffer, "solid", 5) == 0); if (isASCII) { @@ -386,7 +386,6 @@ void STLImporter::LoadASCIIFile(aiNode *root) { 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(); } From 35fb4c93703790d19aa4407016297fe6c0f873eb Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 9 Jun 2020 10:07:25 +0200 Subject: [PATCH 3/9] Remove dead code --- code/AssetLib/STL/STLLoader.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/code/AssetLib/STL/STLLoader.cpp b/code/AssetLib/STL/STLLoader.cpp index 00cfe4b4d..2d710b084 100644 --- a/code/AssetLib/STL/STLLoader.cpp +++ b/code/AssetLib/STL/STLLoader.cpp @@ -375,7 +375,6 @@ void STLImporter::LoadASCIIFile(aiNode *root) { 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 From 42afc40d168b0dfdd26794de4b076156e61ad081 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 9 Jun 2020 10:13:43 +0200 Subject: [PATCH 4/9] Disable warning only for gcc 8.0 or greater --- code/AssetLib/glTF/glTFAsset.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/code/AssetLib/glTF/glTFAsset.h b/code/AssetLib/glTF/glTFAsset.h index 56cf18527..50d977603 100644 --- a/code/AssetLib/glTF/glTFAsset.h +++ b/code/AssetLib/glTF/glTFAsset.h @@ -60,13 +60,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#ifndef RAPIDJSON_HAS_STDSTRING #define RAPIDJSON_HAS_STDSTRING 1 +#endif + +#if (__GNUC__ == 8 && __GNUC_MINOR__ >= 0) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wclass-memaccess" +#endif + #include #include #include + +#if (__GNUC__ == 8 && __GNUC_MINOR__ >= 0) #pragma GCC diagnostic pop +#endif + #ifdef ASSIMP_API # include # include From 620bebb999e16fcf9dfa2c561b12c261e579b204 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 9 Jun 2020 10:14:57 +0200 Subject: [PATCH 5/9] diable warning only for gcc 8.0 or greater --- code/AssetLib/glTF2/glTF2Asset.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/code/AssetLib/glTF2/glTF2Asset.h b/code/AssetLib/glTF2/glTF2Asset.h index 9c1938123..f70421ef2 100644 --- a/code/AssetLib/glTF2/glTF2Asset.h +++ b/code/AssetLib/glTF2/glTF2Asset.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, @@ -63,13 +62,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#ifndef RAPIDJSON_HAS_STDSTRING #define RAPIDJSON_HAS_STDSTRING 1 +#endif + +#if (__GNUC__ == 8 && __GNUC_MINOR__ >= 0) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wclass-memaccess" +#endif + #include #include #include + +#if (__GNUC__ == 8 && __GNUC_MINOR__ >= 0) #pragma GCC diagnostic pop +#endif + #ifdef ASSIMP_API #include #include From 88c1509d69994a8433da53c337c2beeb0a28d232 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 9 Jun 2020 10:15:35 +0200 Subject: [PATCH 6/9] Remove dead code --- code/Common/SceneCombiner.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/code/Common/SceneCombiner.cpp b/code/Common/SceneCombiner.cpp index 2b3b701d5..4f262192b 100644 --- a/code/Common/SceneCombiner.cpp +++ b/code/Common/SceneCombiner.cpp @@ -981,7 +981,6 @@ void GetArrayCopy(Type*& dest, ai_uint num ) { for ( size_t i=0; i Date: Tue, 9 Jun 2020 10:16:05 +0200 Subject: [PATCH 7/9] Remove dead code. --- test/unit/utFindInvalidData.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/unit/utFindInvalidData.cpp b/test/unit/utFindInvalidData.cpp index a31479af7..17a9c0379 100644 --- a/test/unit/utFindInvalidData.cpp +++ b/test/unit/utFindInvalidData.cpp @@ -110,8 +110,6 @@ TEST_F(utFindInvalidDataProcess, testStepNegativeResult) { 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::quiet_NaN()); From f0f6612b81c1eec1ba2ebc8bcdfb227252223174 Mon Sep 17 00:00:00 2001 From: kimkulling Date: Mon, 15 Jun 2020 20:52:11 +0200 Subject: [PATCH 8/9] disable warning for radjson. --- contrib/rapidjson/include/rapidjson/document.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/contrib/rapidjson/include/rapidjson/document.h b/contrib/rapidjson/include/rapidjson/document.h index 93b091f64..473d846e3 100644 --- a/contrib/rapidjson/include/rapidjson/document.h +++ b/contrib/rapidjson/include/rapidjson/document.h @@ -17,6 +17,11 @@ /*! \file document.h */ +#if (__GNUC__ >= 8 && __GNUC_MINOR__ >= 0) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wclass-memaccess" +#endif + #include "reader.h" #include "internal/meta.h" #include "internal/strfunc.h" @@ -2610,4 +2615,8 @@ private: RAPIDJSON_NAMESPACE_END RAPIDJSON_DIAG_POP +#if (__GNUC__ == 8 && __GNUC_MINOR__ >= 0) +#pragma GCC diagnostic pop +#endif + #endif // RAPIDJSON_DOCUMENT_H_ From 524e2e4728a6b62d6fc6e33239031b30f7fc7a6c Mon Sep 17 00:00:00 2001 From: kimkulling Date: Mon, 15 Jun 2020 21:34:49 +0200 Subject: [PATCH 9/9] fix warning, hopefully ... --- code/Common/SceneCombiner.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/code/Common/SceneCombiner.cpp b/code/Common/SceneCombiner.cpp index 4f262192b..5d49baaf4 100644 --- a/code/Common/SceneCombiner.cpp +++ b/code/Common/SceneCombiner.cpp @@ -66,6 +66,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace Assimp { +#if (__GNUC__ >= 8 && __GNUC_MINOR__ >= 0) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wclass-memaccess" +#endif + // ------------------------------------------------------------------------------------------------ // Add a prefix to a string inline @@ -75,7 +80,7 @@ void PrefixString(aiString& string,const char* prefix, unsigned int len) { return; if (len+string.length>=MAXLEN-1) { - ASSIMP_LOG_VERBOSE_DEBUG("Can't add an unique prefix because the string is too long"); + ASSIMP_LOG_VERBOSE_DEBUG("Can't add an unique prefix because the string is too long"); ai_assert(false); return; } @@ -98,8 +103,9 @@ void SceneCombiner::AddNodeHashes(aiNode* node, std::set& hashes) } // Process all children recursively - for (unsigned int i = 0; i < node->mNumChildren;++i) + for (unsigned int i = 0; i < node->mNumChildren;++i) { AddNodeHashes(node->mChildren[i],hashes); + } } // ------------------------------------------------------------------------------------------------ @@ -978,9 +984,7 @@ void GetArrayCopy(Type*& dest, ai_uint num ) { Type* old = dest; dest = new Type[num]; - for ( size_t i=0; imBitangents, dest->mNumVertices ); unsigned int n = 0; - while (dest->HasTextureCoords(n)) - GetArrayCopy( dest->mTextureCoords[n++], dest->mNumVertices ); + while (dest->HasTextureCoords(n)) { + GetArrayCopy( dest->mTextureCoords[n++], dest->mNumVertices ); + } n = 0; - while (dest->HasVertexColors(n)) - GetArrayCopy( dest->mColors[n++], dest->mNumVertices ); + while (dest->HasVertexColors(n)) { + GetArrayCopy( dest->mColors[n++], dest->mNumVertices ); + } // make a deep copy of all bones CopyPtrArray(dest->mBones,dest->mBones,dest->mNumBones); @@ -1343,5 +1349,9 @@ void SceneCombiner::Copy(aiMetadata** _dest, const aiMetadata* src) { } } +#if (__GNUC__ >= 8 && __GNUC_MINOR__ >= 0) +# pragma GCC diagnostic pop +#endif + } // Namespace Assimp