From 722420c5dc65d4f684e311b7ee969936d5b1543c Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 14 Dec 2017 16:51:47 +0100 Subject: [PATCH 1/8] diable unaigned pointer access temprary. --- code/MDLLoader.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/MDLLoader.cpp b/code/MDLLoader.cpp index 2025d79b3..873da4c3e 100644 --- a/code/MDLLoader.cpp +++ b/code/MDLLoader.cpp @@ -416,7 +416,8 @@ void MDLImporter::InternReadFile_Quake1( ) { // get the first frame in the group BE_NCONST MDL::GroupFrame* pcFrames2 = (BE_NCONST MDL::GroupFrame*)pcFrames; - pcFirstFrame = (BE_NCONST MDL::SimpleFrame*)(&pcFrames2->time + pcFrames->type); + //pcFirstFrame = (BE_NCONST MDL::SimpleFrame*)(&pcFrames2->time + pcFrames->type); + ai_assert( false && "Unaligned pointer" ); } BE_NCONST MDL::Vertex* pcVertices = (BE_NCONST MDL::Vertex*) ((pcFirstFrame->name) + sizeof(pcFirstFrame->name)); VALIDATE_FILE_SIZE((const unsigned char*)(pcVertices + pcHeader->num_verts)); From eb0608f2e9c1fa130ba41469783e8c150f40c9f9 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 14 Dec 2017 17:00:16 +0100 Subject: [PATCH 2/8] diable unaigned pointer access temprary, second one. --- code/MDLLoader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/MDLLoader.cpp b/code/MDLLoader.cpp index 873da4c3e..3a9f2c344 100644 --- a/code/MDLLoader.cpp +++ b/code/MDLLoader.cpp @@ -415,7 +415,7 @@ void MDLImporter::InternReadFile_Quake1( ) else { // get the first frame in the group - BE_NCONST MDL::GroupFrame* pcFrames2 = (BE_NCONST MDL::GroupFrame*)pcFrames; + //BE_NCONST MDL::GroupFrame* pcFrames2 = (BE_NCONST MDL::GroupFrame*)pcFrames; //pcFirstFrame = (BE_NCONST MDL::SimpleFrame*)(&pcFrames2->time + pcFrames->type); ai_assert( false && "Unaligned pointer" ); } From 151d71bc697bb61bebc9cd90d890908cfe1ec275 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 14 Dec 2017 17:21:17 +0100 Subject: [PATCH 3/8] fix misalignment in vector2 [] operator. --- include/assimp/vector2.inl | 10 +++++++++- include/assimp/vector3.inl | 1 - 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/assimp/vector2.inl b/include/assimp/vector2.inl index 5ce13eece..ee6c4d2d4 100644 --- a/include/assimp/vector2.inl +++ b/include/assimp/vector2.inl @@ -114,7 +114,15 @@ const aiVector2t& aiVector2t::operator /= (TReal f) { // ------------------------------------------------------------------------------------------------ template TReal aiVector2t::operator[](unsigned int i) const { - return *(&x + i); + switch (i) { + case 0: + return x; + case 1: + return y; + default: + break; + } + return x; } // ------------------------------------------------------------------------------------------------ diff --git a/include/assimp/vector3.inl b/include/assimp/vector3.inl index a074bb23a..2b132c1a5 100644 --- a/include/assimp/vector3.inl +++ b/include/assimp/vector3.inl @@ -142,7 +142,6 @@ AI_FORCE_INLINE aiVector3t& aiVector3t::operator *= (const aiMatri // ------------------------------------------------------------------------------------------------ template AI_FORCE_INLINE TReal aiVector3t::operator[](unsigned int i) const { -// return *(&x + i); switch (i) { case 0: return x; From e0649b68220ff41c24be5a8faf3e03de3b4ebf5b Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 14 Dec 2017 17:42:59 +0100 Subject: [PATCH 4/8] fix misalignment in vector2 [] operator, the non-const one. --- include/assimp/vector2.inl | 58 ++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/include/assimp/vector2.inl b/include/assimp/vector2.inl index ee6c4d2d4..97db2820c 100644 --- a/include/assimp/vector2.inl +++ b/include/assimp/vector2.inl @@ -60,24 +60,28 @@ aiVector2t::operator aiVector2t () const { } // ------------------------------------------------------------------------------------------------ template +inline void aiVector2t::Set( TReal pX, TReal pY) { x = pX; y = pY; } // ------------------------------------------------------------------------------------------------ template +inline TReal aiVector2t::SquareLength() const { return x*x + y*y; } // ------------------------------------------------------------------------------------------------ template +inline TReal aiVector2t::Length() const { return std::sqrt( SquareLength()); } // ------------------------------------------------------------------------------------------------ template +inline aiVector2t& aiVector2t::Normalize() { *this /= Length(); return *this; @@ -85,6 +89,7 @@ aiVector2t& aiVector2t::Normalize() { // ------------------------------------------------------------------------------------------------ template +inline const aiVector2t& aiVector2t::operator += (const aiVector2t& o) { x += o.x; y += o.y; return *this; @@ -92,6 +97,7 @@ const aiVector2t& aiVector2t::operator += (const aiVector2t& o) { // ------------------------------------------------------------------------------------------------ template +inline const aiVector2t& aiVector2t::operator -= (const aiVector2t& o) { x -= o.x; y -= o.y; return *this; @@ -99,6 +105,7 @@ const aiVector2t& aiVector2t::operator -= (const aiVector2t& o) { // ------------------------------------------------------------------------------------------------ template +inline const aiVector2t& aiVector2t::operator *= (TReal f) { x *= f; y *= f; return *this; @@ -106,6 +113,7 @@ const aiVector2t& aiVector2t::operator *= (TReal f) { // ------------------------------------------------------------------------------------------------ template +inline const aiVector2t& aiVector2t::operator /= (TReal f) { x /= f; y /= f; return *this; @@ -113,6 +121,7 @@ const aiVector2t& aiVector2t::operator /= (TReal f) { // ------------------------------------------------------------------------------------------------ template +inline TReal aiVector2t::operator[](unsigned int i) const { switch (i) { case 0: @@ -127,24 +136,36 @@ TReal aiVector2t::operator[](unsigned int i) const { // ------------------------------------------------------------------------------------------------ template +inline TReal& aiVector2t::operator[](unsigned int i) { - return *(&x + i); + switch (i) { + case 0: + return x; + case 1: + return y; + default: + break; + } + return x; } // ------------------------------------------------------------------------------------------------ template +inline bool aiVector2t::operator== (const aiVector2t& other) const { return x == other.x && y == other.y; } // ------------------------------------------------------------------------------------------------ template +inline bool aiVector2t::operator!= (const aiVector2t& other) const { return x != other.x || y != other.y; } // --------------------------------------------------------------------------- template +inline bool aiVector2t::Equal(const aiVector2t& other, TReal epsilon) const { return std::abs(x - other.x) <= epsilon && @@ -153,6 +174,7 @@ bool aiVector2t::Equal(const aiVector2t& other, TReal epsilon) const { // ------------------------------------------------------------------------------------------------ template +inline aiVector2t& aiVector2t::operator= (TReal f) { x = y = f; return *this; @@ -160,6 +182,7 @@ aiVector2t& aiVector2t::operator= (TReal f) { // ------------------------------------------------------------------------------------------------ template +inline const aiVector2t aiVector2t::SymMul(const aiVector2t& o) { return aiVector2t(x*o.x,y*o.y); } @@ -168,65 +191,64 @@ const aiVector2t aiVector2t::SymMul(const aiVector2t& o) { // ------------------------------------------------------------------------------------------------ // symmetric addition template -inline aiVector2t operator + (const aiVector2t& v1, const aiVector2t& v2) -{ +inline +inline aiVector2t operator + (const aiVector2t& v1, const aiVector2t& v2) { return aiVector2t( v1.x + v2.x, v1.y + v2.y); } // ------------------------------------------------------------------------------------------------ // symmetric subtraction template -inline aiVector2t operator - (const aiVector2t& v1, const aiVector2t& v2) -{ +inline +aiVector2t operator - (const aiVector2t& v1, const aiVector2t& v2) { return aiVector2t( v1.x - v2.x, v1.y - v2.y); } // ------------------------------------------------------------------------------------------------ // scalar product template -inline TReal operator * (const aiVector2t& v1, const aiVector2t& v2) -{ +inline +TReal operator * (const aiVector2t& v1, const aiVector2t& v2) { return v1.x*v2.x + v1.y*v2.y; } // ------------------------------------------------------------------------------------------------ // scalar multiplication template -inline aiVector2t operator * ( TReal f, const aiVector2t& v) -{ +inline +aiVector2t operator * ( TReal f, const aiVector2t& v) { return aiVector2t( f*v.x, f*v.y); } // ------------------------------------------------------------------------------------------------ // and the other way around template -inline aiVector2t operator * ( const aiVector2t& v, TReal f) -{ +inline +aiVector2t operator * ( const aiVector2t& v, TReal f) { return aiVector2t( f*v.x, f*v.y); } // ------------------------------------------------------------------------------------------------ // scalar division template -inline aiVector2t operator / ( const aiVector2t& v, TReal f) -{ - +inline +aiVector2t operator / ( const aiVector2t& v, TReal f) { return v * (1/f); } // ------------------------------------------------------------------------------------------------ // vector division template -inline aiVector2t operator / ( const aiVector2t& v, const aiVector2t& v2) -{ +inline +aiVector2t operator / ( const aiVector2t& v, const aiVector2t& v2) { return aiVector2t(v.x / v2.x,v.y / v2.y); } // ------------------------------------------------------------------------------------------------ // vector negation template -inline aiVector2t operator - ( const aiVector2t& v) -{ +inline +aiVector2t operator - ( const aiVector2t& v) { return aiVector2t( -v.x, -v.y); } From 245b9b4bb1a1de421c0b95e92b187c04de8f7af8 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 14 Dec 2017 17:52:47 +0100 Subject: [PATCH 5/8] fix typo. --- include/assimp/vector2.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/assimp/vector2.inl b/include/assimp/vector2.inl index 97db2820c..1682a27ec 100644 --- a/include/assimp/vector2.inl +++ b/include/assimp/vector2.inl @@ -192,7 +192,7 @@ const aiVector2t aiVector2t::SymMul(const aiVector2t& o) { // symmetric addition template inline -inline aiVector2t operator + (const aiVector2t& v1, const aiVector2t& v2) { +aiVector2t operator + (const aiVector2t& v1, const aiVector2t& v2) { return aiVector2t( v1.x + v2.x, v1.y + v2.y); } From bef219a2d9cf40b8927c8bd24ac41ddd69c5aa2b Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 14 Dec 2017 17:59:23 +0100 Subject: [PATCH 6/8] fix access violation in vector2. --- include/assimp/vector2.h | 1 - include/assimp/vector2.inl | 15 --------------- 2 files changed, 16 deletions(-) diff --git a/include/assimp/vector2.h b/include/assimp/vector2.h index 564d1f8b5..df3c41024 100644 --- a/include/assimp/vector2.h +++ b/include/assimp/vector2.h @@ -85,7 +85,6 @@ public: const aiVector2t& operator /= (TReal f); TReal operator[](unsigned int i) const; - TReal& operator[](unsigned int i); bool operator== (const aiVector2t& other) const; bool operator!= (const aiVector2t& other) const; diff --git a/include/assimp/vector2.inl b/include/assimp/vector2.inl index 1682a27ec..d6171955f 100644 --- a/include/assimp/vector2.inl +++ b/include/assimp/vector2.inl @@ -134,21 +134,6 @@ TReal aiVector2t::operator[](unsigned int i) const { return x; } -// ------------------------------------------------------------------------------------------------ -template -inline -TReal& aiVector2t::operator[](unsigned int i) { - switch (i) { - case 0: - return x; - case 1: - return y; - default: - break; - } - return x; -} - // ------------------------------------------------------------------------------------------------ template inline From dec3e2ba42e60be8c4ae3ba2a2f08d32ead77d51 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 14 Dec 2017 18:06:28 +0100 Subject: [PATCH 7/8] XGLLoader: fix const issue when seeting vec2. --- code/XGLLoader.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/code/XGLLoader.cpp b/code/XGLLoader.cpp index 8ef91afac..97fe4fbd5 100644 --- a/code/XGLLoader.cpp +++ b/code/XGLLoader.cpp @@ -904,12 +904,14 @@ aiVector2D XGLImporter::ReadVec2() } const char* s = m_reader->getNodeData(); - for(int i = 0; i < 2; ++i) { + ai_real v[2]; + for(int i = 0; i < 2; ++i) { if(!SkipSpaces(&s)) { LogError("unexpected EOL, failed to parse vec2"); return vec; } - vec[i] = fast_atof(&s); + + v[i] = fast_atof(&s); SkipSpaces(&s); if (i != 1 && *s != ',') { @@ -918,6 +920,8 @@ aiVector2D XGLImporter::ReadVec2() } ++s; } + vec.x = v[0]; + vex.y = v[1]; return vec; } From 5e63ba9a9d762f311e2fd1b9222ceca033abbcee Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 14 Dec 2017 18:10:42 +0100 Subject: [PATCH 8/8] typo. --- code/XGLLoader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/XGLLoader.cpp b/code/XGLLoader.cpp index 97fe4fbd5..809936099 100644 --- a/code/XGLLoader.cpp +++ b/code/XGLLoader.cpp @@ -921,7 +921,7 @@ aiVector2D XGLImporter::ReadVec2() ++s; } vec.x = v[0]; - vex.y = v[1]; + vec.y = v[1]; return vec; }