Fix issue #1623 : crash when loading multiple PLY files

Pointer mGeneratedMesh was not reset to nullptr when transfering ownership
to pScene->mMeshes
pull/1636/head
Alexandre Avenel 2017-12-12 20:48:51 +01:00
parent 89ff8fc05d
commit 50bcaf39fd
1 changed files with 19 additions and 3 deletions

View File

@ -91,9 +91,9 @@ namespace
// ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer
PLYImporter::PLYImporter()
: mBuffer()
, pcDOM()
, mGeneratedMesh(NULL){
: mBuffer(nullptr)
, pcDOM(nullptr)
, mGeneratedMesh(nullptr){
// empty
}
@ -196,7 +196,10 @@ void PLYImporter::InternReadFile(const std::string& pFile,
if (!PLY::DOM::ParseInstance(streamedBuffer, &sPlyDom, this))
{
if (mGeneratedMesh != NULL)
{
delete(mGeneratedMesh);
mGeneratedMesh = nullptr;
}
streamedBuffer.close();
throw DeadlyImportError("Invalid .ply file: Unable to build DOM (#1)");
@ -211,7 +214,10 @@ void PLYImporter::InternReadFile(const std::string& pFile,
if (!PLY::DOM::ParseInstanceBinary(streamedBuffer, &sPlyDom, this, bIsBE))
{
if (mGeneratedMesh != NULL)
{
delete(mGeneratedMesh);
mGeneratedMesh = nullptr;
}
streamedBuffer.close();
throw DeadlyImportError("Invalid .ply file: Unable to build DOM (#2)");
@ -220,7 +226,10 @@ void PLYImporter::InternReadFile(const std::string& pFile,
else
{
if (mGeneratedMesh != NULL)
{
delete(mGeneratedMesh);
mGeneratedMesh = nullptr;
}
streamedBuffer.close();
throw DeadlyImportError("Invalid .ply file: Unknown file format");
@ -230,7 +239,10 @@ void PLYImporter::InternReadFile(const std::string& pFile,
{
AI_DEBUG_INVALIDATE_PTR(this->mBuffer);
if (mGeneratedMesh != NULL)
{
delete(mGeneratedMesh);
mGeneratedMesh = nullptr;
}
streamedBuffer.close();
throw DeadlyImportError("Invalid .ply file: Missing format specification");
@ -252,7 +264,10 @@ void PLYImporter::InternReadFile(const std::string& pFile,
if (mGeneratedMesh->mNumVertices < 3)
{
if (mGeneratedMesh != NULL)
{
delete(mGeneratedMesh);
mGeneratedMesh = nullptr;
}
streamedBuffer.close();
throw DeadlyImportError("Invalid .ply file: Not enough "
@ -289,6 +304,7 @@ void PLYImporter::InternReadFile(const std::string& pFile,
pScene->mNumMeshes = 1;
pScene->mMeshes = new aiMesh*[pScene->mNumMeshes];
pScene->mMeshes[0] = mGeneratedMesh;
mGeneratedMesh = nullptr;
// generate a simple node structure
pScene->mRootNode = new aiNode();