Fix invalid release of mat + mesh.
parent
e51b7d2a61
commit
bcdc79ba73
|
@ -116,6 +116,16 @@ const aiImporterDesc* IRRMeshImporter::GetInfo () const
|
||||||
return &desc;
|
return &desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void releaseMaterial( aiMaterial **mat ) {
|
||||||
|
delete mat;
|
||||||
|
*mat = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void releaseMesh( aiMesh **mesh ) {
|
||||||
|
delete mesh;
|
||||||
|
*mesh = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Imports the given file into the given scene structure.
|
// Imports the given file into the given scene structure.
|
||||||
void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
||||||
|
@ -135,7 +145,7 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
||||||
std::vector<aiMaterial*> materials;
|
std::vector<aiMaterial*> materials;
|
||||||
std::vector<aiMesh*> meshes;
|
std::vector<aiMesh*> meshes;
|
||||||
materials.reserve (5);
|
materials.reserve (5);
|
||||||
meshes.reserve (5);
|
meshes.reserve(5);
|
||||||
|
|
||||||
// temporary data - current mesh buffer
|
// temporary data - current mesh buffer
|
||||||
aiMaterial* curMat = NULL;
|
aiMaterial* curMat = NULL;
|
||||||
|
@ -159,11 +169,10 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
||||||
if (!ASSIMP_stricmp(reader->getNodeName(),"buffer") && (curMat || curMesh)) {
|
if (!ASSIMP_stricmp(reader->getNodeName(),"buffer") && (curMat || curMesh)) {
|
||||||
// end of previous buffer. A material and a mesh should be there
|
// end of previous buffer. A material and a mesh should be there
|
||||||
if ( !curMat || !curMesh) {
|
if ( !curMat || !curMesh) {
|
||||||
DefaultLogger::get()->error("IRRMESH: A buffer must contain a mesh and a material");
|
DefaultLogger::get()->error("IRRMESH: A buffer must contain a mesh and a material");
|
||||||
delete curMat;
|
releaseMaterial( &curMat );
|
||||||
delete curMesh;
|
releaseMesh( &curMesh );
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
materials.push_back(curMat);
|
materials.push_back(curMat);
|
||||||
meshes.push_back(curMesh);
|
meshes.push_back(curMesh);
|
||||||
}
|
}
|
||||||
|
@ -183,7 +192,7 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
||||||
if (!ASSIMP_stricmp(reader->getNodeName(),"material")) {
|
if (!ASSIMP_stricmp(reader->getNodeName(),"material")) {
|
||||||
if (curMat) {
|
if (curMat) {
|
||||||
DefaultLogger::get()->warn("IRRMESH: Only one material description per buffer, please");
|
DefaultLogger::get()->warn("IRRMESH: Only one material description per buffer, please");
|
||||||
delete curMat;curMat = NULL;
|
releaseMaterial( &curMat );
|
||||||
}
|
}
|
||||||
curMat = ParseMaterial(curMatFlags);
|
curMat = ParseMaterial(curMatFlags);
|
||||||
}
|
}
|
||||||
|
@ -195,17 +204,16 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
||||||
// This is possible ... remove the mesh from the list and skip further reading
|
// This is possible ... remove the mesh from the list and skip further reading
|
||||||
DefaultLogger::get()->warn("IRRMESH: Found mesh with zero vertices");
|
DefaultLogger::get()->warn("IRRMESH: Found mesh with zero vertices");
|
||||||
|
|
||||||
delete curMat;curMat = NULL;
|
releaseMaterial( &curMat );
|
||||||
|
releaseMesh( &curMesh );
|
||||||
curMesh = NULL;
|
|
||||||
textMeaning = 0;
|
textMeaning = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
curVertices.reserve (num);
|
curVertices.reserve(num);
|
||||||
curNormals.reserve (num);
|
curNormals.reserve(num);
|
||||||
curColors.reserve (num);
|
curColors.reserve(num);
|
||||||
curUVs.reserve (num);
|
curUVs.reserve(num);
|
||||||
|
|
||||||
// Determine the file format
|
// Determine the file format
|
||||||
const char* t = reader->getAttributeValueSafe("type");
|
const char* t = reader->getAttributeValueSafe("type");
|
||||||
|
@ -240,7 +248,7 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
||||||
vertexFormat = 2;
|
vertexFormat = 2;
|
||||||
}
|
}
|
||||||
else if (ASSIMP_stricmp("standard", t)) {
|
else if (ASSIMP_stricmp("standard", t)) {
|
||||||
delete curMat;
|
releaseMaterial( &curMat );
|
||||||
DefaultLogger::get()->warn("IRRMESH: Unknown vertex format");
|
DefaultLogger::get()->warn("IRRMESH: Unknown vertex format");
|
||||||
}
|
}
|
||||||
else vertexFormat = 0;
|
else vertexFormat = 0;
|
||||||
|
@ -248,7 +256,7 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
||||||
}
|
}
|
||||||
else if (!ASSIMP_stricmp(reader->getNodeName(),"indices")) {
|
else if (!ASSIMP_stricmp(reader->getNodeName(),"indices")) {
|
||||||
if (curVertices.empty() && curMat) {
|
if (curVertices.empty() && curMat) {
|
||||||
delete curMat;
|
releaseMaterial( &curMat );
|
||||||
throw DeadlyImportError("IRRMESH: indices must come after vertices");
|
throw DeadlyImportError("IRRMESH: indices must come after vertices");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,10 +272,10 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
||||||
DefaultLogger::get()->warn("IRRMESH: Found mesh with zero indices");
|
DefaultLogger::get()->warn("IRRMESH: Found mesh with zero indices");
|
||||||
|
|
||||||
// mesh - away
|
// mesh - away
|
||||||
delete curMesh; curMesh = NULL;
|
releaseMesh( &curMesh );
|
||||||
|
|
||||||
// material - away
|
// material - away
|
||||||
delete curMat;curMat = NULL;
|
releaseMaterial( &curMat );
|
||||||
|
|
||||||
textMeaning = 0;
|
textMeaning = 0;
|
||||||
continue;
|
continue;
|
||||||
|
@ -469,7 +477,6 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
// GCC complains here ...
|
// GCC complains here ...
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -480,8 +487,8 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
||||||
if (curMat || curMesh) {
|
if (curMat || curMesh) {
|
||||||
if ( !curMat || !curMesh) {
|
if ( !curMat || !curMesh) {
|
||||||
DefaultLogger::get()->error("IRRMESH: A buffer must contain a mesh and a material");
|
DefaultLogger::get()->error("IRRMESH: A buffer must contain a mesh and a material");
|
||||||
delete curMat;
|
releaseMaterial( &curMat );
|
||||||
delete curMesh;
|
releaseMesh( &curMesh );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
materials.push_back(curMat);
|
materials.push_back(curMat);
|
||||||
|
|
Loading…
Reference in New Issue