From 23c62f07f757ed7b860baf55e9bf2e98bbb806f6 Mon Sep 17 00:00:00 2001 From: Alexander Gessler Date: Fri, 27 Jul 2012 01:49:02 +0200 Subject: [PATCH] - fbx: fix memleak in exception cases. --- code/FBXConverter.cpp | 70 +++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index 7c3ddc6f1..4542632e9 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -129,41 +129,45 @@ private: std::vector nodes; nodes.reserve(conns.size()); - BOOST_FOREACH(const Connection* con, conns) { + try { + BOOST_FOREACH(const Connection* con, conns) { - // ignore object-property links - if(con->PropertyName().length()) { - continue; + // ignore object-property links + if(con->PropertyName().length()) { + continue; + } + + const Object* const object = con->SourceObject(); + if(!object) { + FBXImporter::LogWarn("failed to convert source object for Model link"); + continue; + } + + const Model* const model = dynamic_cast(object); + + if(model) { + aiNode* nd = new aiNode(); + nodes.push_back(nd); + + nd->mName.Set(FixNodeName(model->Name())); + nd->mParent = &parent; + + ConvertTransformation(*model,*nd); + + ConvertModel(*model, *nd); + ConvertNodes(model->ID(), *nd); + } } - const Object* const object = con->SourceObject(); - if(!object) { - FBXImporter::LogWarn("failed to convert source object for node link"); - continue; + if(nodes.size()) { + parent.mChildren = new aiNode*[nodes.size()](); + parent.mNumChildren = static_cast(nodes.size()); + + std::swap_ranges(nodes.begin(),nodes.end(),parent.mChildren); } - - const Model* const model = dynamic_cast(object); - - - if(model) { - aiNode* nd = new aiNode(); - nodes.push_back(nd); - - nd->mName.Set(FixNodeName(model->Name())); - nd->mParent = &parent; - - ConvertTransformation(*model,*nd); - - ConvertModel(*model, *nd); - ConvertNodes(model->ID(), *nd); - } - } - - if(nodes.size()) { - parent.mChildren = new aiNode*[nodes.size()](); - parent.mNumChildren = static_cast(nodes.size()); - - std::swap_ranges(nodes.begin(),nodes.end(),parent.mChildren); + } + catch(std::exception&) { + std::for_each(nodes.begin(),nodes.end(),Util::delete_fun()); } } @@ -173,6 +177,8 @@ private: { const PropertyTable& props = model.Props(); + // XXX this is not complete, need to handle rotation and scaling pivots etc + bool ok; aiVector3D Translation = PropertyGet(props,"Lcl Translation",ok); @@ -640,7 +646,7 @@ private: bones.reserve(sk.Clusters().size()); const bool no_mat_check = materialIndex == NO_MATERIAL_SEPARATION; - ai_assert(!no_mat_check || outputVertStartIndices); + ai_assert(no_mat_check || outputVertStartIndices); try {