From 0f2cea7ba6d046a02bf3bf8813bb1dfbe73fc253 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 6 Sep 2016 10:42:02 +0200 Subject: [PATCH] Blender: revert fix for suspicious crash in blender on windows. --- code/BlenderIntermediate.h | 4 ++-- code/ObjFileImporter.cpp | 43 +++++++++++++++++++++---------------------- code/ObjFileImporter.h | 12 +++--------- 3 files changed, 26 insertions(+), 33 deletions(-) diff --git a/code/BlenderIntermediate.h b/code/BlenderIntermediate.h index 83b10e8..0290185 100644 --- a/code/BlenderIntermediate.h +++ b/code/BlenderIntermediate.h @@ -123,7 +123,7 @@ namespace Blender { struct ObjectCompare { bool operator() (const Object* left, const Object* right) const { - return ::strncmp(left->id.name, right->id.name, strlen( left->id.name ) ) == -1; + return ::strncmp(left->id.name, right->id.name, strlen( left->id.name ) ) == 0; } }; @@ -144,7 +144,7 @@ namespace Blender { struct ObjectCompare { bool operator() (const Object* left, const Object* right) const { - return ::strncmp( left->id.name, right->id.name, strlen( left->id.name ) ) == -1; + return ::strncmp( left->id.name, right->id.name, strlen( left->id.name ) ) == 0; } }; diff --git a/code/ObjFileImporter.cpp b/code/ObjFileImporter.cpp index 2d6c859..a70d69b 100644 --- a/code/ObjFileImporter.cpp +++ b/code/ObjFileImporter.cpp @@ -387,8 +387,7 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel, const ObjFile::Object* pCurrentObject, unsigned int uiMeshIndex, aiMesh* pMesh, - unsigned int numIndices) -{ + unsigned int numIndices) { // Checking preconditions ai_assert( NULL != pCurrentObject ); @@ -398,8 +397,9 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel, // Get current mesh ObjFile::Mesh *pObjMesh = pModel->m_Meshes[ uiMeshIndex ]; - if ( NULL == pObjMesh || pObjMesh->m_uiNumIndices < 1) + if ( NULL == pObjMesh || pObjMesh->m_uiNumIndices < 1 ) { return; + } // Copy vertices of this mesh instance pMesh->mNumVertices = numIndices; @@ -427,27 +427,25 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel, // Copy vertices, normals and textures into aiMesh instance unsigned int newIndex = 0, outIndex = 0; - for ( size_t index=0; index < pObjMesh->m_Faces.size(); index++ ) - { + for ( size_t index=0; index < pObjMesh->m_Faces.size(); index++ ) { // Get source face ObjFile::Face *pSourceFace = pObjMesh->m_Faces[ index ]; // Copy all index arrays - for ( size_t vertexIndex = 0, outVertexIndex = 0; vertexIndex < pSourceFace->m_pVertices->size(); vertexIndex++ ) - { + for ( size_t vertexIndex = 0, outVertexIndex = 0; vertexIndex < pSourceFace->m_pVertices->size(); vertexIndex++ ) { const unsigned int vertex = pSourceFace->m_pVertices->at( vertexIndex ); - if ( vertex >= pModel->m_Vertices.size() ) + if ( vertex >= pModel->m_Vertices.size() ) { throw DeadlyImportError( "OBJ: vertex index out of range" ); + } pMesh->mVertices[ newIndex ] = pModel->m_Vertices[ vertex ]; // Copy all normals - if ( !pModel->m_Normals.empty() && vertexIndex < pSourceFace->m_pNormals->size()) - { + if ( !pModel->m_Normals.empty() && vertexIndex < pSourceFace->m_pNormals->size()) { const unsigned int normal = pSourceFace->m_pNormals->at( vertexIndex ); - if ( normal >= pModel->m_Normals.size() ) - throw DeadlyImportError("OBJ: vertex normal index out of range"); - + if ( normal >= pModel->m_Normals.size() ) { + throw DeadlyImportError( "OBJ: vertex normal index out of range" ); + } pMesh->mNormals[ newIndex ] = pModel->m_Normals[ normal ]; } @@ -544,20 +542,21 @@ void ObjFileImporter::countObjects(const std::vector &rObjects // ------------------------------------------------------------------------------------------------ // Add clamp mode property to material if necessary -void ObjFileImporter::addTextureMappingModeProperty(aiMaterial* mat, aiTextureType type, int clampMode) -{ - ai_assert( NULL != mat); - mat->AddProperty(&clampMode, 1, AI_MATKEY_MAPPINGMODE_U(type, 0)); - mat->AddProperty(&clampMode, 1, AI_MATKEY_MAPPINGMODE_V(type, 0)); +void ObjFileImporter::addTextureMappingModeProperty( aiMaterial* mat, aiTextureType type, int clampMode) { + if ( nullptr == mat ) { + return; + } + + mat->AddProperty( &clampMode, 1, AI_MATKEY_MAPPINGMODE_U( type, 0 ) ); + mat->AddProperty( &clampMode, 1, AI_MATKEY_MAPPINGMODE_V( type, 0 ) ); } // ------------------------------------------------------------------------------------------------ // Creates the material -void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pScene ) -{ - ai_assert( NULL != pScene ); - if ( NULL == pScene ) +void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pScene ) { + if ( NULL == pScene ) { return; + } const unsigned int numMaterials = (unsigned int) pModel->m_MaterialLib.size(); pScene->mNumMaterials = 0; diff --git a/code/ObjFileImporter.h b/code/ObjFileImporter.h index b03d00b..8c48201 100644 --- a/code/ObjFileImporter.h +++ b/code/ObjFileImporter.h @@ -37,8 +37,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ - - #ifndef OBJ_FILE_IMPORTER_H_INC #define OBJ_FILE_IMPORTER_H_INC @@ -49,11 +47,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. struct aiMesh; struct aiNode; -namespace Assimp -{ +namespace Assimp { -namespace ObjFile -{ +namespace ObjFile { struct Object; struct Model; } @@ -62,8 +58,7 @@ struct Model; /// \class ObjFileImporter /// \brief Imports a waveform obj file // ------------------------------------------------------------------------------------------------ -class ObjFileImporter : public BaseImporter -{ +class ObjFileImporter : public BaseImporter { public: /// \brief Default constructor ObjFileImporter(); @@ -77,7 +72,6 @@ public: bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const; private: - //! \brief Appends the supported extension. const aiImporterDesc* GetInfo () const; -- 2.7.4