[NUI] fix TCT crash issue 70/164770/2
authordongsug.song <dongsug.song@samsung.com>
Thu, 21 Dec 2017 02:53:23 +0000 (11:53 +0900)
committerdongsug.song <dongsug.song@samsung.com>
Thu, 21 Dec 2017 02:55:19 +0000 (11:55 +0900)
Change-Id: Ia21049ab623b7bea0ed4038db95b64cb09e71323
Signed-off-by: dongsug.song <dongsug.song@samsung.com>
src/Tizen.NUI/src/public/Animation.cs
src/Tizen.NUI/src/public/Timer.cs

index aef2822..75db7f9 100755 (executable)
@@ -47,6 +47,14 @@ namespace Tizen.NUI
             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
         }
 
+        ~Animation()
+        {
+            if (_animationFinishedEventCallback != null)
+            {
+                _finishedSignal?.Disconnect(_finishedCallbackOfNative);
+            }
+        }
+
         /// <summary>
         /// To make animation instance be disposed.
         /// </summary>
@@ -55,12 +63,11 @@ namespace Tizen.NUI
         {
             if (_animationFinishedEventCallback != null)
             {
-                FinishedSignal().Disconnect(_finishedCallbackOfNative);
+                _finishedSignal?.Disconnect(_finishedCallbackOfNative);
             }
 
             if (_animationProgressReachedEventCallback != null)
             {
-
                 ProgressReachedSignal().Disconnect(_animationProgressReachedEventCallback);
             }
 
@@ -68,6 +75,7 @@ namespace Tizen.NUI
             {
                 return;
             }
+
             if(type == DisposeTypes.Explicit)
             {
                 //Called by User
@@ -84,7 +92,7 @@ namespace Tizen.NUI
             {
                 this.Clear();
                 this.Reset();
-                NUILog.Error("Now Animation is playing! Clear and Reset here!");
+                NUILog.Error("Animation().Clear & Reset here!");
                 //throw new System.InvalidOperationException("Animation Instance should not be disposed until getting Finished event. Should be a global variable");
             }
 
@@ -125,6 +133,7 @@ namespace Tizen.NUI
         private event EventHandler _animationFinishedEventHandler;
 
         private System.IntPtr _finishedCallbackOfNative;
+        private AnimationSignal _finishedSignal;
 
         /**
         * @brief Event for the finished signal which can be used to subscribe or unsubscribe the event handler.
@@ -137,7 +146,8 @@ namespace Tizen.NUI
             {
                 if (_animationFinishedEventHandler == null && disposed == false)
                 {
-                    FinishedSignal().Connect(_finishedCallbackOfNative);
+                    _finishedSignal = FinishedSignal();
+                    _finishedSignal?.Connect(_finishedCallbackOfNative);
                 }
                 _animationFinishedEventHandler += value;
             }
@@ -145,9 +155,9 @@ namespace Tizen.NUI
             {
                 _animationFinishedEventHandler -= value;
 
-                if (_animationFinishedEventHandler == null && FinishedSignal().Empty() == false)
+                if (_animationFinishedEventHandler == null && _finishedSignal?.Empty() == false)
                 {
-                    FinishedSignal().Disconnect(_finishedCallbackOfNative);
+                    _finishedSignal?.Disconnect(_finishedCallbackOfNative);
                 }
             }
         }
index 3ca9ff4..7d1824b 100755 (executable)
@@ -44,13 +44,14 @@ namespace Tizen.NUI
 
             _timerTickCallbackDelegate = OnTick;
             _timerTickCallbackOfNative = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(_timerTickCallbackDelegate);
-
-            NUILog.Debug($"(0x{swigCPtr.Handle:X})Timer() contructor!");
         }
 
         ~Timer()
         {
-            NUILog.Debug($"(0x{swigCPtr.Handle:X})Timer() distructor!, disposed={disposed}");
+            if (_timerTickCallbackDelegate != null)
+            {
+                _timerSignal?.Disconnect(_timerTickCallbackOfNative);
+            }
         }
 
         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Timer obj)
@@ -64,11 +65,9 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         protected override void Dispose(DisposeTypes type)
         {
-            NUILog.Debug($"(0x{swigCPtr.Handle:X}) Timer.Dispose(type={type}, disposed={disposed})");
-
             if (_timerTickCallbackDelegate != null)
             {
-                TickSignal().Disconnect(_timerTickCallbackOfNative);
+                _timerSignal?.Disconnect(_timerTickCallbackOfNative);
             }
 
             if (disposed)
@@ -116,6 +115,7 @@ namespace Tizen.NUI
         private TickCallbackDelegate _timerTickCallbackDelegate;
 
         private System.IntPtr _timerTickCallbackOfNative;
+        private TimerSignalType _timerSignal;
 
         /// <summary>
         /// @brief Event for the ticked signal, which can be used to subscribe or unsubscribe the event handler
@@ -128,16 +128,17 @@ namespace Tizen.NUI
             {
                 if (_timerTickEventHandler == null && disposed == false)
                 {
-                    TickSignal().Connect(_timerTickCallbackOfNative);
+                    _timerSignal = TickSignal();
+                    _timerSignal?.Connect(_timerTickCallbackOfNative);
                 }
                 _timerTickEventHandler += value;
             }
             remove
             {
                 _timerTickEventHandler -= value;
-                if (_timerTickEventHandler == null && TickSignal().Empty() == false)
+                if (_timerTickEventHandler == null && _timerSignal?.Empty() == false)
                 {
-                    TickSignal().Disconnect(_timerTickCallbackOfNative);
+                    _timerSignal?.Disconnect(_timerTickCallbackOfNative);
                 }
             }
         }
@@ -148,7 +149,7 @@ namespace Tizen.NUI
 
             if (played == false)
             {
-                Tizen.Log.Fatal("NUI", $"(0x{swigCPtr.Handle:X}) OnTick() is called even played is false!");
+                Tizen.Log.Fatal("NUI", $"OnTick() is called even played is false!");
                 //throw new System.InvalidOperationException($"OnTick() excpetion!");
             }
 
@@ -169,8 +170,6 @@ namespace Tizen.NUI
         public Timer(uint milliSec) : this(NDalicPINVOKE.Timer_New(milliSec), true)
         {
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-
-            NUILog.Debug($"(0x{swigCPtr.Handle:X})  Timer({milliSec}) Constructor!");
         }
         internal Timer(Timer timer) : this(NDalicPINVOKE.new_Timer__SWIG_1(Timer.getCPtr(timer)), true)
         {
@@ -228,8 +227,6 @@ namespace Tizen.NUI
         /// <param name="milliSec">MilliSec interval in milliseconds.</param>
         internal void SetInterval(uint milliSec)
         {
-            NUILog.Debug($"(0x{swigCPtr.Handle:X})SetInterval({milliSec})");
-
             played = true;
 
             NDalicPINVOKE.Timer_SetInterval(swigCPtr, milliSec);