[NUI] fix animation finished callback null reference crash 51/163651/1
authordongsug.song <dongsug.song@samsung.com>
Tue, 12 Dec 2017 16:01:07 +0000 (01:01 +0900)
committerhuiyu,eun <huiyu.eun@samsung.com>
Tue, 12 Dec 2017 16:04:12 +0000 (01:04 +0900)
Change-Id: Ice6383394ec99d5752cde31df445c9d5c7b41d7a
Signed-off-by: dongsug.song <dongsug.song@samsung.com>
src/Tizen.NUI/src/internal/AnimationSignal.cs
src/Tizen.NUI/src/public/Animation.cs

index 13d6f60..67eb06d 100755 (executable)
@@ -123,6 +123,19 @@ namespace Tizen.NUI
             }
         }
 
+
+        public void Connect(System.IntPtr callback)
+        {
+            NDalicPINVOKE.AnimationSignal_Connect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, callback));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+        public void Disconnect(System.IntPtr callback)
+        {
+            NDalicPINVOKE.AnimationSignal_Disconnect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, callback));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+
         public void Disconnect(System.Delegate func)
         {
             System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(func);
index 9caa1ee..aef2822 100755 (executable)
@@ -37,6 +37,9 @@ namespace Tizen.NUI
         internal Animation(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Animation_SWIGUpcast(cPtr), cMemoryOwn)
         {
             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
+
+            _animationFinishedEventCallback = OnFinished;
+            _finishedCallbackOfNative = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(_animationFinishedEventCallback);
         }
 
         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Animation obj)
@@ -50,6 +53,17 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         protected override void Dispose(DisposeTypes type)
         {
+            if (_animationFinishedEventCallback != null)
+            {
+                FinishedSignal().Disconnect(_finishedCallbackOfNative);
+            }
+
+            if (_animationProgressReachedEventCallback != null)
+            {
+
+                ProgressReachedSignal().Disconnect(_animationProgressReachedEventCallback);
+            }
+
             if(disposed)
             {
                 return;
@@ -66,18 +80,7 @@ namespace Tizen.NUI
 
             }
 
-            if (_animationFinishedEventCallback != null)
-            {
-                FinishedSignal().Disconnect(_animationFinishedEventCallback);
-            }
-
-            if (_animationProgressReachedEventCallback != null)
-            {
-
-                ProgressReachedSignal().Disconnect(_animationProgressReachedEventCallback);
-            }
-
-            if(this)
+            if (this)
             {
                 this.Clear();
                 this.Reset();
@@ -120,6 +123,9 @@ namespace Tizen.NUI
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         private delegate void AnimationFinishedEventCallbackType(IntPtr data);
         private event EventHandler _animationFinishedEventHandler;
+
+        private System.IntPtr _finishedCallbackOfNative;
+
         /**
         * @brief Event for the finished signal which can be used to subscribe or unsubscribe the event handler.
         * The finished signal is emitted when an animation's animations have finished.
@@ -129,12 +135,9 @@ namespace Tizen.NUI
         {
             add
             {
-                if (_animationFinishedEventHandler == null)
+                if (_animationFinishedEventHandler == null && disposed == false)
                 {
-                    NUILog.Debug("[add before]FinishedSignal().Empty=" + FinishedSignal().Empty() + " GetConnectionCount=" + FinishedSignal().GetConnectionCount());
-                    _animationFinishedEventCallback = OnFinished;
-                    FinishedSignal().Connect(_animationFinishedEventCallback);
-                    NUILog.Debug("[add after]FinishedSignal().Empty=" + FinishedSignal().Empty() + " GetConnectionCount=" + FinishedSignal().GetConnectionCount());
+                    FinishedSignal().Connect(_finishedCallbackOfNative);
                 }
                 _animationFinishedEventHandler += value;
             }
@@ -144,9 +147,7 @@ namespace Tizen.NUI
 
                 if (_animationFinishedEventHandler == null && FinishedSignal().Empty() == false)
                 {
-                    NUILog.Debug("[remove before]FinishedSignal().Empty=" + FinishedSignal().Empty() + " GetConnectionCount=" + FinishedSignal().GetConnectionCount());
-                    FinishedSignal().Disconnect(_animationFinishedEventCallback);
-                    NUILog.Debug("[remove after]FinishedSignal().Empty=" + FinishedSignal().Empty() + " GetConnectionCount=" + FinishedSignal().GetConnectionCount());
+                    FinishedSignal().Disconnect(_finishedCallbackOfNative);
                 }
             }
         }
@@ -174,10 +175,8 @@ namespace Tizen.NUI
             {
                 if (_animationProgressReachedEventHandler == null)
                 {
-                    NUILog.Debug("[add before]ProgressReachedSignal().Empty=" + FinishedSignal().Empty() + " GetConnectionCount=" + FinishedSignal().GetConnectionCount());
                     _animationProgressReachedEventCallback = OnProgressReached;
                     ProgressReachedSignal().Connect(_animationProgressReachedEventCallback);
-                    NUILog.Debug("[add after]ProgressReachedSignal().Empty=" + FinishedSignal().Empty() + " GetConnectionCount=" + FinishedSignal().GetConnectionCount());
                 }
 
                 _animationProgressReachedEventHandler += value;
@@ -188,9 +187,7 @@ namespace Tizen.NUI
 
                 if (_animationProgressReachedEventHandler == null && ProgressReachedSignal().Empty() == false)
                 {
-                    NUILog.Debug("[remove before]ProgressReachedSignal().Empty=" + FinishedSignal().Empty() + " GetConnectionCount=" + FinishedSignal().GetConnectionCount());
                     ProgressReachedSignal().Disconnect(_animationProgressReachedEventCallback);
-                    NUILog.Debug("[remove after]ProgressReachedSignal().Empty=" + FinishedSignal().Empty() + " GetConnectionCount=" + FinishedSignal().GetConnectionCount());
                 }
             }
         }