Merge branch 'master' of github.com:assimp/assimp into issue_1470

pull/1474/head
Jared Mulconry 2017-10-05 19:34:37 +11:00
commit a824b79508
19 changed files with 83 additions and 28 deletions

View File

@ -1,6 +1,6 @@
function generate() function generate()
{ {
cmake -G "Unix Makefiles" -DASSIMP_NO_EXPORT=$TRAVIS_NO_EXPORT -DBUILD_SHARED_LIBS=$SHARED_BUILD -DASSIMP_COVERALLS=$ENABLE_COVERALLS -DASSIMP_ERROR=ON cmake -G "Unix Makefiles" -DASSIMP_NO_EXPORT=$TRAVIS_NO_EXPORT -DBUILD_SHARED_LIBS=$SHARED_BUILD -DASSIMP_COVERALLS=$ENABLE_COVERALLS -DASSIMP_ERROR=ON -DASSIMP_ASAN=$ASAN
} }
if [ $ANDROID ]; then if [ $ANDROID ]; then

View File

@ -39,16 +39,16 @@ matrix:
include: include:
- os: linux - os: linux
compiler: gcc compiler: gcc
env: LINUX=1 TRAVIS_NO_EXPORT=YES ENABLE_COVERALLS=ON env: LINUX=1 TRAVIS_NO_EXPORT=YES ENABLE_COVERALLS=ON ASAN=OFF
- os: linux - os: linux
compiler: gcc compiler: gcc
env: LINUX=1 TRAVIS_NO_EXPORT=NO ENABLE_COVERALLS=OFF env: LINUX=1 TRAVIS_NO_EXPORT=NO ENABLE_COVERALLS=OFF ASAN=ON
- os: linux - os: linux
compiler: gcc compiler: gcc
env: LINUX=1 SHARED_BUILD=ON TRAVIS_NO_EXPORT=NO ENABLE_COVERALLS=OFF env: LINUX=1 SHARED_BUILD=ON TRAVIS_NO_EXPORT=NO ENABLE_COVERALLS=OFF ASAN=OFF
- os: linux - os: linux
compiler: gcc compiler: gcc
env: LINUX=1 SHARED_BUILD=ON TRAVIS_NO_EXPORT=NO ENABLE_COVERALLS=OFF env: LINUX=1 SHARED_BUILD=ON TRAVIS_NO_EXPORT=NO ENABLE_COVERALLS=OFF ASAN=OFF
install: install:
- if [ $ANDROID ]; then wget -c http://dl.google.com/android/ndk/android-ndk-${PV}-${PLATF}.tar.bz2 && tar xf android-ndk-${PV}-${PLATF}.tar.bz2 ; fi - if [ $ANDROID ]; then wget -c http://dl.google.com/android/ndk/android-ndk-${PV}-${PLATF}.tar.bz2 && tar xf android-ndk-${PV}-${PLATF}.tar.bz2 ; fi

View File

@ -82,6 +82,10 @@ OPTION ( ASSIMP_WERROR
"Treat warnings as errors." "Treat warnings as errors."
OFF OFF
) )
OPTION ( ASSIMP_ASAN
"Enable AddressSanitizer."
OFF
)
OPTION ( SYSTEM_IRRXML OPTION ( SYSTEM_IRRXML
"Use system installed Irrlicht/IrrXML library." "Use system installed Irrlicht/IrrXML library."
OFF OFF
@ -203,6 +207,11 @@ IF ((CMAKE_C_COMPILER_ID MATCHES "GNU") AND NOT CMAKE_COMPILER_IS_MINGW)
ELSEIF(MSVC) ELSEIF(MSVC)
# enable multi-core compilation with MSVC # enable multi-core compilation with MSVC
add_compile_options(/MP) add_compile_options(/MP)
# disable "elements of array '' will be default initialized" warning on MSVC2013
IF(MSVC12)
add_compile_options(/wd4351)
ENDIF()
ELSEIF ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) ELSEIF ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fvisibility=hidden -fPIC -Wall -Wno-long-long -std=c++11" ) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fvisibility=hidden -fPIC -Wall -Wno-long-long -std=c++11" )
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
@ -219,8 +228,17 @@ if (ASSIMP_COVERALLS)
endif() endif()
if (ASSIMP_WERROR) if (ASSIMP_WERROR)
IF (MSVC)
add_compile_options(/WX)
ELSE()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
ENDIF()
endif()
if (ASSIMP_ASAN)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
endif() endif()
INCLUDE (FindPkgMacros) INCLUDE (FindPkgMacros)

View File

@ -29,8 +29,8 @@ install:
build_script: build_script:
- cd c:\projects\assimp - cd c:\projects\assimp
- if "%platform%" equ "x64" (cmake CMakeLists.txt -G "Visual Studio %Configuration% Win64") - if "%platform%" equ "x64" (cmake CMakeLists.txt -DASSIMP_WERROR=ON -G "Visual Studio %Configuration% Win64")
- if "%platform%" equ "x86" (cmake CMakeLists.txt -G "Visual Studio %Configuration%") - if "%platform%" equ "x86" (cmake CMakeLists.txt -DASSIMP_WERROR=ON -G "Visual Studio %Configuration%")
- if "%platform%" equ "x64" (msbuild /m /p:Configuration=Release /p:Platform="x64" Assimp.sln) - if "%platform%" equ "x64" (msbuild /m /p:Configuration=Release /p:Platform="x64" Assimp.sln)
- if "%platform%" equ "x86" (msbuild /m /p:Configuration=Release /p:Platform="Win32" Assimp.sln) - if "%platform%" equ "x86" (msbuild /m /p:Configuration=Release /p:Platform="Win32" Assimp.sln)

View File

@ -82,6 +82,20 @@ static const aiImporterDesc desc = {
//#define DEBUG_B3D //#define DEBUG_B3D
template<typename T>
void DeleteAllBarePointers(std::vector<T>& x)
{
for(auto p : x)
{
delete p;
}
}
B3DImporter::~B3DImporter()
{
DeleteAllBarePointers(_animations);
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
bool B3DImporter::CanRead( const std::string& pFile, IOSystem* /*pIOHandler*/, bool /*checkSig*/) const{ bool B3DImporter::CanRead( const std::string& pFile, IOSystem* /*pIOHandler*/, bool /*checkSig*/) const{
@ -558,13 +572,19 @@ aiNode *B3DImporter::ReadNODE( aiNode *parent ){
void B3DImporter::ReadBB3D( aiScene *scene ){ void B3DImporter::ReadBB3D( aiScene *scene ){
_textures.clear(); _textures.clear();
_materials.clear(); _materials.clear();
_vertices.clear(); _vertices.clear();
_meshes.clear(); _meshes.clear();
DeleteAllBarePointers(_nodes);
_nodes.clear(); _nodes.clear();
_nodeAnims.clear(); _nodeAnims.clear();
DeleteAllBarePointers(_animations);
_animations.clear(); _animations.clear();
string t=ReadChunk(); string t=ReadChunk();

View File

@ -59,6 +59,8 @@ namespace Assimp{
class B3DImporter : public BaseImporter{ class B3DImporter : public BaseImporter{
public: public:
B3DImporter() = default;
virtual ~B3DImporter();
virtual bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const; virtual bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const;

View File

@ -193,14 +193,14 @@ bool MakeVerboseFormatProcess::MakeVerboseFormat(aiMesh* pcMesh)
p = 0; p = 0;
while (pcMesh->HasTextureCoords(p)) while (pcMesh->HasTextureCoords(p))
{ {
delete pcMesh->mTextureCoords[p]; delete[] pcMesh->mTextureCoords[p];
pcMesh->mTextureCoords[p] = apvTextureCoords[p]; pcMesh->mTextureCoords[p] = apvTextureCoords[p];
++p; ++p;
} }
p = 0; p = 0;
while (pcMesh->HasVertexColors(p)) while (pcMesh->HasVertexColors(p))
{ {
delete pcMesh->mColors[p]; delete[] pcMesh->mColors[p];
pcMesh->mColors[p] = apvColorSets[p]; pcMesh->mColors[p] = apvColorSets[p];
++p; ++p;
} }

View File

@ -634,7 +634,7 @@ void PretransformVertices::Execute( aiScene* pScene)
aiNode* newRoot = new aiNode(); aiNode* newRoot = new aiNode();
newRoot->mName = pScene->mRootNode->mName; newRoot->mName = pScene->mRootNode->mName;
delete pScene->mRootNode; delete pScene->mRootNode;
pScene->mRootNode = new aiNode(); pScene->mRootNode = newRoot;
if (1 == pScene->mNumMeshes && !pScene->mNumLights && !pScene->mNumCameras) if (1 == pScene->mNumMeshes && !pScene->mNumLights && !pScene->mNumCameras)
{ {

View File

@ -511,7 +511,7 @@ namespace glTF2
/// \fn ~SEncodedRegion() /// \fn ~SEncodedRegion()
/// Destructor. /// Destructor.
~SEncodedRegion() { delete [] DecodedData; } ~SEncodedRegion() { delete[] DecodedData; }
}; };
/******************* Variables *******************/ /******************* Variables *******************/

View File

@ -313,7 +313,7 @@ inline void Buffer::Read(Value& obj, Asset& r)
if (dataURI.base64) { if (dataURI.base64) {
uint8_t* data = 0; uint8_t* data = 0;
this->byteLength = Util::DecodeBase64(dataURI.data, dataURI.dataLength, data); this->byteLength = Util::DecodeBase64(dataURI.data, dataURI.dataLength, data);
this->mData.reset(data); this->mData.reset(data, std::default_delete<uint8_t[]>());
if (statedLength > 0 && this->byteLength != statedLength) { if (statedLength > 0 && this->byteLength != statedLength) {
throw DeadlyImportError("GLTF: buffer \"" + id + "\", expected " + to_string(statedLength) + throw DeadlyImportError("GLTF: buffer \"" + id + "\", expected " + to_string(statedLength) +
@ -326,7 +326,7 @@ inline void Buffer::Read(Value& obj, Asset& r)
" bytes, but found " + to_string(dataURI.dataLength)); " bytes, but found " + to_string(dataURI.dataLength));
} }
this->mData.reset(new uint8_t[dataURI.dataLength]); this->mData.reset(new uint8_t[dataURI.dataLength], std::default_delete<uint8_t[]>());
memcpy( this->mData.get(), dataURI.data, dataURI.dataLength ); memcpy( this->mData.get(), dataURI.data, dataURI.dataLength );
} }
} }
@ -357,7 +357,7 @@ inline bool Buffer::LoadFromStream(IOStream& stream, size_t length, size_t baseO
stream.Seek(baseOffset, aiOrigin_SET); stream.Seek(baseOffset, aiOrigin_SET);
} }
mData.reset(new uint8_t[byteLength]); mData.reset(new uint8_t[byteLength], std::default_delete<uint8_t[]>());
if (stream.Read(mData.get(), byteLength, 1) != 1) { if (stream.Read(mData.get(), byteLength, 1) != 1) {
return false; return false;
@ -432,7 +432,7 @@ uint8_t* new_data;
// Copy data which place after replacing part. // Copy data which place after replacing part.
memcpy(&new_data[pBufferData_Offset + pReplace_Count], &mData.get()[pBufferData_Offset + pBufferData_Count], pBufferData_Offset); memcpy(&new_data[pBufferData_Offset + pReplace_Count], &mData.get()[pBufferData_Offset + pBufferData_Count], pBufferData_Offset);
// Apply new data // Apply new data
mData.reset(new_data); mData.reset(new_data, std::default_delete<uint8_t[]>());
byteLength = new_data_size; byteLength = new_data_size;
return true; return true;
@ -451,7 +451,7 @@ inline void Buffer::Grow(size_t amount)
if (amount <= 0) return; if (amount <= 0) return;
uint8_t* b = new uint8_t[byteLength + amount]; uint8_t* b = new uint8_t[byteLength + amount];
if (mData) memcpy(b, mData.get(), byteLength); if (mData) memcpy(b, mData.get(), byteLength);
mData.reset(b); mData.reset(b, std::default_delete<uint8_t[]>());
byteLength += amount; byteLength += amount;
} }

View File

@ -341,7 +341,7 @@ inline bool Buffer::LoadFromStream(IOStream& stream, size_t length, size_t baseO
stream.Seek(baseOffset, aiOrigin_SET); stream.Seek(baseOffset, aiOrigin_SET);
} }
mData.reset(new uint8_t[byteLength]); mData.reset(new uint8_t[byteLength], std::default_delete<uint8_t[]>());
if (stream.Read(mData.get(), byteLength, 1) != 1) { if (stream.Read(mData.get(), byteLength, 1) != 1) {
return false; return false;

View File

@ -60,7 +60,7 @@ public:
static aiScene *createDefaultTestModel( float &opacity ) { static aiScene *createDefaultTestModel( float &opacity ) {
aiScene *scene( new aiScene ); aiScene *scene( new aiScene );
scene->mNumMaterials = 1; scene->mNumMaterials = 1;
scene->mMaterials = new aiMaterial*; scene->mMaterials = new aiMaterial*[scene->mNumMaterials];
scene->mMaterials[ 0 ] = new aiMaterial; scene->mMaterials[ 0 ] = new aiMaterial;
aiColor3D color( 1, 0, 0 ); aiColor3D color( 1, 0, 0 );
EXPECT_EQ( AI_SUCCESS, scene->mMaterials[ 0 ]->AddProperty( &color, 1, AI_MATKEY_COLOR_DIFFUSE ) ); EXPECT_EQ( AI_SUCCESS, scene->mMaterials[ 0 ]->AddProperty( &color, 1, AI_MATKEY_COLOR_DIFFUSE ) );
@ -70,7 +70,7 @@ public:
EXPECT_EQ( AI_SUCCESS, scene->mMaterials[ 0 ]->AddProperty( &opacity, 1, AI_MATKEY_OPACITY ) ); EXPECT_EQ( AI_SUCCESS, scene->mMaterials[ 0 ]->AddProperty( &opacity, 1, AI_MATKEY_OPACITY ) );
scene->mNumMeshes = 1; scene->mNumMeshes = 1;
scene->mMeshes = new aiMesh*; scene->mMeshes = new aiMesh*[scene->mNumMeshes];
scene->mMeshes[ 0 ] = new aiMesh; scene->mMeshes[ 0 ] = new aiMesh;
scene->mMeshes[ 0 ]->mMaterialIndex = 0; scene->mMeshes[ 0 ]->mMaterialIndex = 0;
scene->mMeshes[ 0 ]->mPrimitiveTypes = aiPrimitiveType_TRIANGLE; scene->mMeshes[ 0 ]->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
@ -80,7 +80,7 @@ public:
scene->mMeshes[ 0 ]->mVertices[ 1 ] = aiVector3D( 0, 1, 0 ); scene->mMeshes[ 0 ]->mVertices[ 1 ] = aiVector3D( 0, 1, 0 );
scene->mMeshes[ 0 ]->mVertices[ 2 ] = aiVector3D( 0, 0, 1 ); scene->mMeshes[ 0 ]->mVertices[ 2 ] = aiVector3D( 0, 0, 1 );
scene->mMeshes[ 0 ]->mNumFaces = 1; scene->mMeshes[ 0 ]->mNumFaces = 1;
scene->mMeshes[ 0 ]->mFaces = new aiFace; scene->mMeshes[ 0 ]->mFaces = new aiFace[scene->mMeshes[ 0 ]->mNumFaces];
scene->mMeshes[ 0 ]->mFaces[ 0 ].mNumIndices = 3; scene->mMeshes[ 0 ]->mFaces[ 0 ].mNumIndices = 3;
scene->mMeshes[ 0 ]->mFaces[ 0 ].mIndices = new unsigned int[ 3 ]; scene->mMeshes[ 0 ]->mFaces[ 0 ].mIndices = new unsigned int[ 3 ];
scene->mMeshes[ 0 ]->mFaces[ 0 ].mIndices[ 0 ] = 0; scene->mMeshes[ 0 ]->mFaces[ 0 ].mIndices[ 0 ] = 0;
@ -89,7 +89,7 @@ public:
scene->mRootNode = new aiNode; scene->mRootNode = new aiNode;
scene->mRootNode->mNumMeshes = 1; scene->mRootNode->mNumMeshes = 1;
scene->mRootNode->mMeshes = new unsigned int( 0 ); scene->mRootNode->mMeshes = new unsigned int[scene->mRootNode->mNumMeshes]{ 0 };
return scene; return scene;
} }

View File

@ -74,6 +74,7 @@ TEST_F( utIssues, OpacityBugWhenExporting_727 ) {
EXPECT_EQ( AI_SUCCESS, newScene->mMaterials[ 0 ]->Get( AI_MATKEY_OPACITY, newOpacity ) ); EXPECT_EQ( AI_SUCCESS, newScene->mMaterials[ 0 ]->Get( AI_MATKEY_OPACITY, newOpacity ) );
EXPECT_EQ( opacity, newOpacity ); EXPECT_EQ( opacity, newOpacity );
} }
delete scene;
} }
#endif // ASSIMP_BUILD_NO_EXPORT #endif // ASSIMP_BUILD_NO_EXPORT

View File

@ -73,7 +73,7 @@ TEST_F(MaterialSystemTest, testFloatArrayProperty)
{ {
float pf[] = {0.0f,1.0f,2.0f,3.0f}; float pf[] = {0.0f,1.0f,2.0f,3.0f};
unsigned int pMax = sizeof(pf) / sizeof(float); unsigned int pMax = sizeof(pf) / sizeof(float);
this->pcMat->AddProperty(&pf,pMax,"testKey2"); this->pcMat->AddProperty(pf,pMax,"testKey2");
pf[0] = pf[1] = pf[2] = pf[3] = 12.0f; pf[0] = pf[1] = pf[2] = pf[3] = 12.0f;
EXPECT_EQ(AI_SUCCESS, pcMat->Get("testKey2",0,0,pf,&pMax)); EXPECT_EQ(AI_SUCCESS, pcMat->Get("testKey2",0,0,pf,&pMax));
@ -97,7 +97,7 @@ TEST_F(MaterialSystemTest, testIntArrayProperty)
{ {
int pf[] = {0,1,2,3}; int pf[] = {0,1,2,3};
unsigned int pMax = sizeof(pf) / sizeof(int); unsigned int pMax = sizeof(pf) / sizeof(int);
this->pcMat->AddProperty(&pf,pMax,"testKey4"); this->pcMat->AddProperty(pf,pMax,"testKey4");
pf[0] = pf[1] = pf[2] = pf[3] = 12; pf[0] = pf[1] = pf[2] = pf[3] = 12;
EXPECT_EQ(AI_SUCCESS, pcMat->Get("testKey4",0,0,pf,&pMax)); EXPECT_EQ(AI_SUCCESS, pcMat->Get("testKey4",0,0,pf,&pMax));

View File

@ -237,6 +237,15 @@ TEST_F( utObjImportExport, obj_import_test ) {
differ.showReport(); differ.showReport();
m_im->FreeScene(); m_im->FreeScene();
for(unsigned int i = 0; i < expected->mNumMeshes; ++i)
{
delete expected->mMeshes[i];
}
delete[] expected->mMeshes;
expected->mMeshes = nullptr;
delete[] expected->mMaterials;
expected->mMaterials = nullptr;
delete expected;
} }
TEST_F( utObjImportExport, issue1111_no_mat_name_Test ) { TEST_F( utObjImportExport, issue1111_no_mat_name_Test ) {

View File

@ -106,8 +106,9 @@ TEST_F( utObjTools, countComponents_TwoLines_Success ) {
TestObjFileParser test_parser; TestObjFileParser test_parser;
std::string data( "-2.061493116917992e-15 -0.9009688496589661 \\\n-0.4338837265968323" ); std::string data( "-2.061493116917992e-15 -0.9009688496589661 \\\n-0.4338837265968323" );
std::vector<char> buffer; std::vector<char> buffer;
buffer.resize( data.size() ); buffer.resize( data.size() + 1 );
::memcpy( &buffer[ 0 ], &data[ 0 ], data.size() ); ::memcpy( &buffer[ 0 ], &data[ 0 ], data.size() );
buffer[ buffer.size() - 1 ] = '\0';
test_parser.setBuffer( buffer ); test_parser.setBuffer( buffer );
size_t numComps = test_parser.testGetNumComponentsInDataDefinition(); size_t numComps = test_parser.testGetNumComponentsInDataDefinition();

View File

@ -72,4 +72,5 @@ TEST_F( utRevmoveVCProcess, issue1266_ProcessMeshTest_NoCrash ) {
scene->mMeshes[ 0 ] = mesh; scene->mMeshes[ 0 ] = mesh;
RemoveVCProcess *process = new RemoveVCProcess; RemoveVCProcess *process = new RemoveVCProcess;
process->Execute( scene ); process->Execute( scene );
} delete scene;
}

View File

@ -42,6 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "UnitTestPCH.h" #include "UnitTestPCH.h"
#include <assimp/SceneCombiner.h> #include <assimp/SceneCombiner.h>
#include <assimp/mesh.h> #include <assimp/mesh.h>
#include <memory>
using namespace ::Assimp; using namespace ::Assimp;
@ -63,8 +64,10 @@ TEST_F( utSceneCombiner, MergeMeshes_ValidNames_Test ) {
mesh3->mName.Set( "mesh_3" ); mesh3->mName.Set( "mesh_3" );
merge_list.push_back( mesh3 ); merge_list.push_back( mesh3 );
aiMesh *out( nullptr ); std::unique_ptr<aiMesh> out;
SceneCombiner::MergeMeshes( &out, 0, merge_list.begin(), merge_list.end() ); aiMesh* ptr = nullptr;
SceneCombiner::MergeMeshes( &ptr, 0, merge_list.begin(), merge_list.end() );
out.reset(ptr);
std::string outName = out->mName.C_Str(); std::string outName = out->mName.C_Str();
EXPECT_EQ( "mesh_1.mesh_2.mesh_3", outName ); EXPECT_EQ( "mesh_1.mesh_2.mesh_3", outName );
} }

View File

@ -92,7 +92,7 @@ TEST_F(SharedPPDataTest, testPODProperty)
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
TEST_F(SharedPPDataTest, testPropertyPointer) TEST_F(SharedPPDataTest, testPropertyPointer)
{ {
int *i = new int[35]; int *i = new int;
shared->AddProperty("test16",i); shared->AddProperty("test16",i);
int* o; int* o;
EXPECT_TRUE(shared->GetProperty("test16",o)); EXPECT_TRUE(shared->GetProperty("test16",o));