Browse Source

Fixed child nodes not deleted if the importer failed to add them to the scene root node.

Marc-Antoine Lortie 5 years ago
parent
commit
9deb8fb786
1 changed files with 15 additions and 0 deletions
  1. 15 0
      code/MDL/HalfLife/HL1MDLLoader.cpp

+ 15 - 0
code/MDL/HalfLife/HL1MDLLoader.cpp

@@ -124,6 +124,17 @@ void HL1MDLLoader::release_resources() {
         delete[] anim_headers_;
         anim_headers_ = nullptr;
     }
+
+    if (rootnode_children_.size()) {
+        // Here, it means that the nodes were not added to the
+        // scene root node. We still have to delete them.
+        for (auto it = rootnode_children_.begin(); it != rootnode_children_.end(); ++it) {
+            if (*it)
+                delete *it;
+        }
+        // Ensure this happens only once.
+        rootnode_children_.clear();
+    }
 }
 
 // ------------------------------------------------------------------------------------------------
@@ -171,6 +182,10 @@ void HL1MDLLoader::load_file() {
             scene_->mRootNode->addChildren(
                     static_cast<unsigned int>(rootnode_children_.size()),
                     rootnode_children_.data());
+
+            // Clear the list of nodes so they will not be destroyed
+            // when resources are released.
+            rootnode_children_.clear();
         }
 
         release_resources();