Fix memory leak

pull/5169/head
Alex 2023-07-03 11:11:34 +00:00
parent d3ee157342
commit ca781a5860
5 changed files with 12 additions and 13 deletions

View File

@ -1258,7 +1258,7 @@ void IRRImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
batch.LoadAll(); batch.LoadAll();
// Allocate a temporary scene data structure // Allocate a temporary scene data structure
aiScene *tempScene = new aiScene(); std::unique_ptr<aiScene> tempScene(new aiScene());
tempScene->mRootNode = new aiNode(); tempScene->mRootNode = new aiNode();
tempScene->mRootNode->mName.Set("<IRRRoot>"); tempScene->mRootNode->mName.Set("<IRRRoot>");

View File

@ -854,7 +854,7 @@ void LWSImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
// and build the final output graph by attaching the loaded external // and build the final output graph by attaching the loaded external
// files to ourselves. first build a master graph // files to ourselves. first build a master graph
aiScene *master = new aiScene(); std::unique_ptr<aiScene> master(new aiScene());
aiNode *nd = master->mRootNode = new aiNode(); aiNode *nd = master->mRootNode = new aiNode();
// allocate storage for cameras&lights // allocate storage for cameras&lights
@ -899,11 +899,11 @@ void LWSImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
// convert the master scene to RH // convert the master scene to RH
MakeLeftHandedProcess monster_cheat; MakeLeftHandedProcess monster_cheat;
monster_cheat.Execute(master); monster_cheat.Execute(master.get());
// .. ccw // .. ccw
FlipWindingOrderProcess flipper; FlipWindingOrderProcess flipper;
flipper.Execute(master); flipper.Execute(master.get());
// OK ... finally build the output graph // OK ... finally build the output graph
SceneCombiner::MergeScenes(&pScene, master, attach, SceneCombiner::MergeScenes(&pScene, master, attach,

View File

@ -554,7 +554,7 @@ bool MD3Importer::ReadMultipartFile() {
batch.LoadAll(); batch.LoadAll();
// now construct a dummy scene to place these three parts in // now construct a dummy scene to place these three parts in
aiScene *master = new aiScene(); std::unique_ptr<aiScene> master(new aiScene());
aiNode *nd = master->mRootNode = new aiNode(); aiNode *nd = master->mRootNode = new aiNode();
nd->mName.Set("<MD3_Player>"); nd->mName.Set("<MD3_Player>");
@ -633,7 +633,6 @@ bool MD3Importer::ReadMultipartFile() {
delete scene_upper; delete scene_upper;
delete scene_lower; delete scene_lower;
delete scene_head; delete scene_head;
delete master;
if (failure == mod_filename) { if (failure == mod_filename) {
throw DeadlyImportError("MD3: failure to read multipart host file"); throw DeadlyImportError("MD3: failure to read multipart host file");

View File

@ -190,7 +190,7 @@ void SceneCombiner::MergeScenes(aiScene **_dest, std::vector<aiScene *> &src, un
*_dest = new aiScene(); *_dest = new aiScene();
// Create a dummy scene to serve as master for the others // Create a dummy scene to serve as master for the others
aiScene *master = new aiScene(); std::unique_ptr<aiScene> master(new aiScene());
master->mRootNode = new aiNode(); master->mRootNode = new aiNode();
master->mRootNode->mName.Set("<MergeRoot>"); master->mRootNode->mName.Set("<MergeRoot>");
@ -250,7 +250,7 @@ void SceneCombiner::AttachToGraph(aiScene *master, std::vector<NodeAttachmentInf
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void SceneCombiner::MergeScenes(aiScene **_dest, aiScene *master, std::vector<AttachmentInfo> &srcList, unsigned int flags) { void SceneCombiner::MergeScenes(aiScene **_dest, std::unique_ptr<aiScene>& master, std::vector<AttachmentInfo> &srcList, unsigned int flags) {
if (nullptr == _dest) { if (nullptr == _dest) {
return; return;
} }
@ -258,9 +258,9 @@ void SceneCombiner::MergeScenes(aiScene **_dest, aiScene *master, std::vector<At
// if _dest points to nullptr allocate a new scene. Otherwise clear the old and reuse it // if _dest points to nullptr allocate a new scene. Otherwise clear the old and reuse it
if (srcList.empty()) { if (srcList.empty()) {
if (*_dest) { if (*_dest) {
SceneCombiner::CopySceneFlat(_dest, master); SceneCombiner::CopySceneFlat(_dest, master.get());
} else } else
*_dest = master; *_dest = master.release();
return; return;
} }
if (*_dest) { if (*_dest) {
@ -272,7 +272,7 @@ void SceneCombiner::MergeScenes(aiScene **_dest, aiScene *master, std::vector<At
aiScene *dest = *_dest; aiScene *dest = *_dest;
std::vector<SceneHelper> src(srcList.size() + 1); std::vector<SceneHelper> src(srcList.size() + 1);
src[0].scene = master; src[0].scene = master.release();
for (unsigned int i = 0; i < srcList.size(); ++i) { for (unsigned int i = 0; i < srcList.size(); ++i) {
src[i + 1] = SceneHelper(srcList[i].scene); src[i + 1] = SceneHelper(srcList[i].scene);
} }
@ -608,7 +608,7 @@ void SceneCombiner::MergeScenes(aiScene **_dest, aiScene *master, std::vector<At
} }
// Now build the output graph // Now build the output graph
AttachToGraph(master, nodes); AttachToGraph(master.get(), nodes);
dest->mRootNode = master->mRootNode; dest->mRootNode = master->mRootNode;
// Check whether we succeeded at building the output graph // Check whether we succeeded at building the output graph

View File

@ -223,7 +223,7 @@ public:
* deletes the input scenes afterwards. There may be duplicate scenes. * deletes the input scenes afterwards. There may be duplicate scenes.
* @param flags Combination of the AI_INT_MERGE_SCENE flags defined above * @param flags Combination of the AI_INT_MERGE_SCENE flags defined above
*/ */
static void MergeScenes(aiScene **dest, aiScene *master, static void MergeScenes(aiScene **dest, std::unique_ptr<aiScene>& master,
std::vector<AttachmentInfo> &src, std::vector<AttachmentInfo> &src,
unsigned int flags = 0); unsigned int flags = 0);