[Tizen](Vector) Fix memory leak issue 56/222456/1 accepted/tizen/5.5/unified/20200121.041235 submit/tizen_5.5/20200120.082613
authorHeeyong Song <heeyong.song@samsung.com>
Wed, 15 Jan 2020 06:32:07 +0000 (15:32 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Wed, 15 Jan 2020 06:32:10 +0000 (15:32 +0900)
The reference count of mRenderedTexture can be 0 in Render method which is called in the worker thread.
In the case, the render object of the Texture is not destoyed.

Ensure the texture object is destoyed in the main thread

Change-Id: I34bb9101a7c673b796639a9f702f61f636264a13

dali-extension/vector-animation-renderer/tizen-vector-animation-renderer.cpp
dali-extension/vector-animation-renderer/tizen-vector-animation-renderer.h

index 640d087..44ade4f 100755 (executable)
@@ -58,6 +58,7 @@ TizenVectorAnimationRenderer::TizenVectorAnimationRenderer()
   mRenderer(),
   mTexture(),
   mRenderedTexture(),
+  mPreviousTexture(),
   mTargetSurface(),
   mVectorRenderer(),
   mUploadCompletedSignal(),
@@ -79,6 +80,7 @@ TizenVectorAnimationRenderer::~TizenVectorAnimationRenderer()
   Dali::Mutex::ScopedLock lock( mMutex );
 
   ResetBuffers();
+  DALI_LOG_RELEASE_INFO( "TizenVectorAnimationRenderer::~TizenVectorAnimationRenderer: this = %p\n", this );
 }
 
 bool TizenVectorAnimationRenderer::Initialize( const std::string& url )
@@ -88,7 +90,7 @@ bool TizenVectorAnimationRenderer::Initialize( const std::string& url )
   mVectorRenderer = rlottie::Animation::loadFromFile( mUrl );
   if( !mVectorRenderer )
   {
-    DALI_LOG_ERROR( "Failed to load a Lottie file [%s]\n", mUrl.c_str() );
+    DALI_LOG_ERROR( "Failed to load a Lottie file [%s] [%p]\n", mUrl.c_str(), this );
     return false;
   }
 
@@ -116,6 +118,7 @@ void TizenVectorAnimationRenderer::Finalize()
   mRenderer.Reset();
   mTexture.Reset();
   mRenderedTexture.Reset();
+  mPreviousTexture.Reset();
   mVectorRenderer.reset();
 
   mTargetSurface = nullptr;
@@ -249,6 +252,7 @@ bool TizenVectorAnimationRenderer::Render( uint32_t frameNumber )
 
     if( !mResourceReady )
     {
+      mPreviousTexture = mRenderedTexture;  // It is used to destroy the object in the main thread.
       mRenderedTexture = mTexture;
       mResourceReady = true;
       mResourceReadyTriggered = true;
@@ -354,6 +358,8 @@ void TizenVectorAnimationRenderer::NotifyEvent()
 
     mUploadCompletedSignal.Emit();
   }
+
+  mPreviousTexture.Reset();
 }
 
 void TizenVectorAnimationRenderer::SetShader()
index 970de2e..3fdcc90 100755 (executable)
@@ -143,6 +143,7 @@ private:
   Dali::Renderer                         mRenderer;              ///< Renderer
   Dali::Texture                          mTexture;               ///< Texture
   Dali::Texture                          mRenderedTexture;       ///< Rendered Texture
+  Dali::Texture                          mPreviousTexture;       ///< Previous rendered texture
   NativeImageSourceQueuePtr              mTargetSurface;         ///< The target surface
   std::unique_ptr< rlottie::Animation >  mVectorRenderer;        ///< The vector animation renderer
   UploadCompletedSignalType              mUploadCompletedSignal; ///< Upload completed signal