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.
void IRRMeshImporter::InternReadFile( const std::string& pFile,
std::vector<aiMaterial*> materials;
std::vector<aiMesh*> meshes;
materials.reserve (5);
- meshes.reserve (5);
+ meshes.reserve(5);
// temporary data - current mesh buffer
aiMaterial* curMat = NULL;
if (!ASSIMP_stricmp(reader->getNodeName(),"buffer") && (curMat || curMesh)) {
// end of previous buffer. A material and a mesh should be there
if ( !curMat || !curMesh) {
- DefaultLogger::get()->error("IRRMESH: A buffer must contain a mesh and a material");
- delete curMat;
- delete curMesh;
- }
- else {
+ DefaultLogger::get()->error("IRRMESH: A buffer must contain a mesh and a material");
+ releaseMaterial( &curMat );
+ releaseMesh( &curMesh );
+ } else {
materials.push_back(curMat);
meshes.push_back(curMesh);
}
if (!ASSIMP_stricmp(reader->getNodeName(),"material")) {
if (curMat) {
DefaultLogger::get()->warn("IRRMESH: Only one material description per buffer, please");
- delete curMat;curMat = NULL;
+ releaseMaterial( &curMat );
}
curMat = ParseMaterial(curMatFlags);
}
// This is possible ... remove the mesh from the list and skip further reading
DefaultLogger::get()->warn("IRRMESH: Found mesh with zero vertices");
- delete curMat;curMat = NULL;
-
- curMesh = NULL;
+ releaseMaterial( &curMat );
+ releaseMesh( &curMesh );
textMeaning = 0;
continue;
}
- curVertices.reserve (num);
- curNormals.reserve (num);
- curColors.reserve (num);
- curUVs.reserve (num);
+ curVertices.reserve(num);
+ curNormals.reserve(num);
+ curColors.reserve(num);
+ curUVs.reserve(num);
// Determine the file format
const char* t = reader->getAttributeValueSafe("type");
vertexFormat = 2;
}
else if (ASSIMP_stricmp("standard", t)) {
- delete curMat;
+ releaseMaterial( &curMat );
DefaultLogger::get()->warn("IRRMESH: Unknown vertex format");
}
else vertexFormat = 0;
}
else if (!ASSIMP_stricmp(reader->getNodeName(),"indices")) {
if (curVertices.empty() && curMat) {
- delete curMat;
+ releaseMaterial( &curMat );
throw DeadlyImportError("IRRMESH: indices must come after vertices");
}
DefaultLogger::get()->warn("IRRMESH: Found mesh with zero indices");
// mesh - away
- delete curMesh; curMesh = NULL;
+ releaseMesh( &curMesh );
// material - away
- delete curMat;curMat = NULL;
+ releaseMaterial( &curMat );
textMeaning = 0;
continue;
break;
default:
-
// GCC complains here ...
break;
if (curMat || curMesh) {
if ( !curMat || !curMesh) {
DefaultLogger::get()->error("IRRMESH: A buffer must contain a mesh and a material");
- delete curMat;
- delete curMesh;
+ releaseMaterial( &curMat );
+ releaseMesh( &curMesh );
}
else {
materials.push_back(curMat);