diff --git a/code/ObjFileImporter.cpp b/code/ObjFileImporter.cpp index 10c463c36..11f4b9487 100644 --- a/code/ObjFileImporter.cpp +++ b/code/ObjFileImporter.cpp @@ -474,7 +474,6 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel, if ( !pModel->m_TextureCoord.empty() && vertexIndex < pSourceFace->m_texturCoords.size()) { const unsigned int tex = pSourceFace->m_texturCoords.at( vertexIndex ); - ai_assert( tex < pModel->m_TextureCoord.size() ); if ( tex >= pModel->m_TextureCoord.size() ) throw DeadlyImportError("OBJ: texture coordinate index out of range"); diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index d89d52977..2b9873bc1 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -60,7 +60,7 @@ const std::string ObjFileParser::DEFAULT_MATERIAL = AI_DEFAULT_MATERIAL_NAME; ObjFileParser::ObjFileParser() : m_DataIt() , m_DataItEnd() -, m_pModel( NULL ) +, m_pModel( nullptr ) , m_uiLine( 0 ) , m_pIO( nullptr ) , m_progress( nullptr ) @@ -73,7 +73,7 @@ ObjFileParser::ObjFileParser( IOStreamBuffer &streamBuffer, const std::str const std::string &originalObjFileName) : m_DataIt(), m_DataItEnd(), - m_pModel(NULL), + m_pModel(nullptr), m_uiLine(0), m_pIO( io ), m_progress(progress), @@ -82,7 +82,7 @@ ObjFileParser::ObjFileParser( IOStreamBuffer &streamBuffer, const std::str std::fill_n(m_buffer,Buffersize,0); // Create the model instance to store all the data - m_pModel = new ObjFile::Model(); + m_pModel.reset(new ObjFile::Model()); m_pModel->m_ModelName = modelName; // create default material and store it @@ -96,8 +96,6 @@ ObjFileParser::ObjFileParser( IOStreamBuffer &streamBuffer, const std::str } ObjFileParser::~ObjFileParser() { - delete m_pModel; - m_pModel = NULL; } void ObjFileParser::setBuffer( std::vector &buffer ) { @@ -106,7 +104,7 @@ void ObjFileParser::setBuffer( std::vector &buffer ) { } ObjFile::Model *ObjFileParser::GetModel() const { - return m_pModel; + return m_pModel.get(); } void ObjFileParser::parseFile( IOStreamBuffer &streamBuffer ) { @@ -353,7 +351,8 @@ void ObjFileParser::getHomogeneousVector3( std::vector &point3d_arra copyNextWord( m_buffer, Buffersize ); w = ( ai_real ) fast_atof( m_buffer ); - ai_assert( w != 0 ); + if (w == 0) + throw DeadlyImportError("OBJ: Invalid component in homogeneous vector (Division by zero)"); point3d_array.push_back( aiVector3D( x/w, y/w, z/w ) ); m_DataIt = skipLine( m_DataIt, m_DataItEnd, m_uiLine ); @@ -478,8 +477,6 @@ void ObjFileParser::getFace( aiPrimitiveType type ) { } else { //On error, std::atoi will return 0 which is not a valid value delete face; - delete m_pModel; - m_pModel = nullptr; throw DeadlyImportError("OBJ: Invalid face indice"); } @@ -641,7 +638,7 @@ void ObjFileParser::getMaterialLib() { m_pIO->Close( pFile ); // Importing the material library - ObjFileMtlImporter mtlImporter( buffer, strMatName, m_pModel ); + ObjFileMtlImporter mtlImporter( buffer, strMatName, m_pModel.get() ); } // ------------------------------------------------------------------- diff --git a/code/ObjFileParser.h b/code/ObjFileParser.h index fa5b3ca31..15332a1df 100644 --- a/code/ObjFileParser.h +++ b/code/ObjFileParser.h @@ -44,6 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include #include #include @@ -145,7 +146,7 @@ private: //! Iterator to end position of buffer DataArrayIt m_DataItEnd; //! Pointer to model instance - ObjFile::Model *m_pModel; + std::unique_ptr m_pModel; //! Current line (for debugging) unsigned int m_uiLine; //! Helper buffer diff --git a/contrib/zlib/zlib.h b/contrib/zlib/zlib.h index 577d81e3b..2d6bb2976 100644 --- a/contrib/zlib/zlib.h +++ b/contrib/zlib/zlib.h @@ -77,6 +77,9 @@ extern "C" { the consistency of the compressed data, so the library should never crash even in the case of corrupted input. */ +#ifdef __ANDROID__ +using zcrc_t = unsigned_long; +#endif typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); typedef void (*free_func) OF((voidpf opaque, voidpf address)); diff --git a/test/unit/utObjImportExport.cpp b/test/unit/utObjImportExport.cpp index dd8adcd80..a6c91fed6 100644 --- a/test/unit/utObjImportExport.cpp +++ b/test/unit/utObjImportExport.cpp @@ -330,6 +330,18 @@ TEST_F(utObjImportExport, homogeneous_coordinates_Test) { EXPECT_EQ(vertice.z, 0.8f); } +TEST_F(utObjImportExport, homogeneous_coordinates_divide_by_zero_Test) { + static const std::string ObjModel = + "v -0.500000 0.000000 0.400000 0.\n" + "v -0.500000 0.000000 -0.800000 1.00000\n" + "v 0.500000 1.000000 -0.800000 0.5000\n" + "f 1 2 3\nB"; + + Assimp::Importer myimporter; + const aiScene *scene = myimporter.ReadFileFromMemory(ObjModel.c_str(), ObjModel.size(), aiProcess_ValidateDataStructure); + EXPECT_EQ(nullptr, scene); +} + TEST_F(utObjImportExport, 0based_array_Test) { static const std::string ObjModel = "v -0.500000 0.000000 0.400000\n"