Make rasterize callback as unique_ptr 22/291522/2
authorEunki, Hong <eunkiki.hong@samsung.com>
Tue, 18 Apr 2023 03:52:06 +0000 (12:52 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Tue, 18 Apr 2023 04:34:38 +0000 (13:34 +0900)
When Rasterize callback register into VectorAnimationManager, and
visual was destroyed, the callback base memory might not be deleted.

To avoid this case, let we make the callback's ownership as
VectorAnimationManager.

Change-Id: Ia2d09856e989ac29f8c39cd5cabb2af29d1ed80d
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp
dali-toolkit/internal/visuals/animated-vector-image/vector-animation-manager.cpp
dali-toolkit/internal/visuals/animated-vector-image/vector-animation-manager.h

index 7244829..1263fbd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -118,6 +118,7 @@ AnimatedVectorImageVisual::~AnimatedVectorImageVisual()
     if(mEventCallback)
     {
       mFactoryCache.GetVectorAnimationManager().UnregisterEventCallback(mEventCallback);
+      mEventCallback = nullptr;
     }
 
     // Finalize animation task and disconnect the signal in the main thread
index 7971b4d..50e6471 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -49,10 +49,6 @@ VectorAnimationManager::VectorAnimationManager()
 
 VectorAnimationManager::~VectorAnimationManager()
 {
-  for(auto&& iter : mEventCallbacks)
-  {
-    delete iter;
-  }
   mEventCallbacks.clear();
 
   if(mProcessorRegistered)
@@ -93,7 +89,7 @@ VectorAnimationThread& VectorAnimationManager::GetVectorAnimationThread()
 
 void VectorAnimationManager::RegisterEventCallback(CallbackBase* callback)
 {
-  mEventCallbacks.push_back(callback);
+  mEventCallbacks.emplace_back(std::unique_ptr<Dali::CallbackBase>(callback));
 
   if(!mProcessorRegistered)
   {
@@ -104,7 +100,11 @@ void VectorAnimationManager::RegisterEventCallback(CallbackBase* callback)
 
 void VectorAnimationManager::UnregisterEventCallback(CallbackBase* callback)
 {
-  auto iter = std::find(mEventCallbacks.begin(), mEventCallbacks.end(), callback);
+  auto iter = std::find_if(mEventCallbacks.begin(),
+                           mEventCallbacks.end(),
+                           [callback](const std::unique_ptr<CallbackBase>& element) {
+                             return element.get() == callback;
+                           });
   if(iter != mEventCallbacks.end())
   {
     mEventCallbacks.erase(iter);
@@ -125,7 +125,6 @@ void VectorAnimationManager::Process(bool postProcessor)
   for(auto&& iter : mEventCallbacks)
   {
     CallbackBase::Execute(*iter);
-    delete iter;
   }
   mEventCallbacks.clear();
 
index fe6b87a..593517c 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_VECTOR_ANIMATION_MANAGER_H
 
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -102,10 +102,10 @@ private:
   VectorAnimationManager& operator=(const VectorAnimationManager& manager) = delete;
 
 private:
-  std::vector<CallbackBase*>             mEventCallbacks;
-  std::vector<LifecycleObserver*>        mLifecycleObservers;
-  std::unique_ptr<VectorAnimationThread> mVectorAnimationThread;
-  bool                                   mProcessorRegistered;
+  std::vector<std::unique_ptr<CallbackBase>> mEventCallbacks;
+  std::vector<LifecycleObserver*>            mLifecycleObservers;
+  std::unique_ptr<VectorAnimationThread>     mVectorAnimationThread;
+  bool                                       mProcessorRegistered;
 };
 
 } // namespace Internal