Browse Source

Fix: Removing double delete of texture items.

Textures were being double deleted after a merge scene because the
texture array wasn't being properly deleted at the end of merging.
Furthermore, the texture array was being sized to the number of
materials instead of the number of textures.
Scott Baldric 4 years ago
parent
commit
aae3788247
1 changed files with 4 additions and 2 deletions
  1. 4 2
      code/Common/SceneCombiner.cpp

+ 4 - 2
code/Common/SceneCombiner.cpp

@@ -45,7 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 // possible as new fields are added to assimp structures.
 // possible as new fields are added to assimp structures.
 
 
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
-/** 
+/**
   * @file Implements Assimp::SceneCombiner. This is a smart utility
   * @file Implements Assimp::SceneCombiner. This is a smart utility
   *       class that combines multiple scenes, meshes, ... into one. Currently
   *       class that combines multiple scenes, meshes, ... into one. Currently
   *       these utilities are used by the IRR and LWS loaders and the
   *       these utilities are used by the IRR and LWS loaders and the
@@ -359,7 +359,7 @@ void SceneCombiner::MergeScenes(aiScene **_dest, aiScene *master, std::vector<At
 
 
     // generate the output texture list + an offset table for all texture indices
     // generate the output texture list + an offset table for all texture indices
     if (dest->mNumTextures) {
     if (dest->mNumTextures) {
-        aiTexture **pip = dest->mTextures = new aiTexture *[dest->mNumMaterials];
+        aiTexture **pip = dest->mTextures = new aiTexture *[dest->mNumTextures];
         cnt = 0;
         cnt = 0;
         for (unsigned int n = 0; n < src.size(); ++n) {
         for (unsigned int n = 0; n < src.size(); ++n) {
             SceneHelper *cur = &src[n];
             SceneHelper *cur = &src[n];
@@ -638,6 +638,8 @@ void SceneCombiner::MergeScenes(aiScene **_dest, aiScene *master, std::vector<At
         deleteMe->mMaterials = nullptr;
         deleteMe->mMaterials = nullptr;
         delete[] deleteMe->mAnimations;
         delete[] deleteMe->mAnimations;
         deleteMe->mAnimations = nullptr;
         deleteMe->mAnimations = nullptr;
+        delete[] deleteMe->mTextures;
+        deleteMe->mTextures = nullptr;
 
 
         deleteMe->mRootNode = nullptr;
         deleteMe->mRootNode = nullptr;