Guard textureId during CheckForWaitingTexture
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / texture-manager / texture-manager-impl.cpp
index ab237a3..33405be 100644 (file)
@@ -1149,6 +1149,12 @@ void TextureManager::CheckForWaitingTexture(TextureManager::TextureInfo& maskTex
           pixelBuffers.push_back(textureInfo.pixelBuffer);
           UploadTextures(pixelBuffers, textureInfo);
 
+          // Increase reference counts for notify required textureId.
+          // Now we can assume that we don't remove & re-assign this textureId
+          // during NotifyObserver signal emit.
+          maskTextureInfo.referenceCount++;
+          textureInfo.referenceCount++;
+
           notifyRequiredTextureIds.push_back(textureInfo.textureId);
         }
       }
@@ -1160,6 +1166,12 @@ void TextureManager::CheckForWaitingTexture(TextureManager::TextureInfo& maskTex
         pixelBuffers.push_back(textureInfo.pixelBuffer);
         UploadTextures(pixelBuffers, textureInfo);
 
+        // Increase reference counts for notify required textureId.
+        // Now we can assume that we don't remove & re-assign this textureId
+        // during NotifyObserver signal emit.
+        maskTextureInfo.referenceCount++;
+        textureInfo.referenceCount++;
+
         notifyRequiredTextureIds.push_back(textureInfo.textureId);
       }
     }
@@ -1175,6 +1187,12 @@ void TextureManager::CheckForWaitingTexture(TextureManager::TextureInfo& maskTex
       NotifyObservers(textureInfo, true);
     }
   }
+
+  // Decrease reference count
+  for(const auto textureId : notifyRequiredTextureIds)
+  {
+    Remove(textureId, nullptr);
+  }
 }
 
 void TextureManager::ApplyMask(TextureManager::TextureInfo& textureInfo, const TextureManager::TextureId& maskTextureId)