[4.0] add depense code for TriggerEvent callback null reference issue 31/163931/1
authordongsug.song <dongsug.song@samsung.com>
Thu, 14 Dec 2017 06:35:29 +0000 (15:35 +0900)
committerdongsug.song <dongsug.song@samsung.com>
Thu, 14 Dec 2017 06:35:29 +0000 (15:35 +0900)
Change-Id: If2576f22ba10cf23cc0724df4ccf2513a68c30e1
Signed-off-by: dongsug.song <dongsug.song@samsung.com>
src/Tizen.NUI/src/internal/Application.cs
src/Tizen.NUI/src/internal/TimerSignalType.cs
src/Tizen.NUI/src/public/Timer.cs

index b6174b0..1378245 100755 (executable)
@@ -520,19 +520,17 @@ namespace Tizen.NUI
                 Tizen.Log.Fatal("NUI", "Dali and NUI are version mismatched!");
             }
 
-            NUIApplicationInitEventArgs e = new NUIApplicationInitEventArgs();
+            // Initialize DisposeQueue Singleton class. This is also required to create DisposeQueue on main thread.
+            DisposeQueue.Instance.Initialize();
 
+            NUIApplicationInitEventArgs e = new NUIApplicationInitEventArgs();
             // Populate all members of "e" (NUIApplicationInitEventArgs) with real data
             e.Application = Application.GetApplicationFromPtr(data);
-
             if (_applicationInitEventHandler != null)
             {
                 //here we send all data to user event handlers
                 _applicationInitEventHandler(this, e);
             }
-
-            // Initialize DisposeQueue Singleton class. This is also required to create DisposeQueue on main thread.
-            DisposeQueue.Instance.Initialize();
         }
 
         /**
index fda4dd7..aae2fa5 100755 (executable)
@@ -133,6 +133,19 @@ namespace Tizen.NUI
             }
         }
 
+        public void Connect(System.IntPtr callback)
+        {
+            NDalicPINVOKE.TimerSignalType_Connect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, callback));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        public void Disconnect(System.IntPtr callback)
+        {
+            NDalicPINVOKE.TimerSignalType_Disconnect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, callback));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+
         public bool Emit()
         {
             bool ret = NDalicPINVOKE.TimerSignalType_Emit(swigCPtr);
index 4d095c1..3ca9ff4 100755 (executable)
@@ -41,6 +41,16 @@ namespace Tizen.NUI
         internal Timer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Timer_SWIGUpcast(cPtr), cMemoryOwn)
         {
             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
+
+            _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}");
         }
 
         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Timer obj)
@@ -54,6 +64,13 @@ 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);
+            }
+
             if (disposed)
             {
                 return;
@@ -70,11 +87,6 @@ namespace Tizen.NUI
             //You should not access any managed member here except static instance.
             //because the execution order of Finalizes is non-deterministic.
 
-            if (_timerTickCallbackDelegate != null)
-            {
-                TickSignal().Disconnect(_timerTickCallbackDelegate);
-            }
-
             if (swigCPtr.Handle != global::System.IntPtr.Zero)
             {
                 if (swigCMemOwn)
@@ -103,6 +115,8 @@ namespace Tizen.NUI
         private EventHandlerWithReturnType<object, TickEventArgs, bool> _timerTickEventHandler;
         private TickCallbackDelegate _timerTickCallbackDelegate;
 
+        private System.IntPtr _timerTickCallbackOfNative;
+
         /// <summary>
         /// @brief Event for the ticked signal, which can be used to subscribe or unsubscribe the event handler
         /// provided by the user. The ticked signal is emitted after specified time interval.<br />
@@ -112,10 +126,9 @@ namespace Tizen.NUI
         {
             add
             {
-                if (_timerTickEventHandler == null)
+                if (_timerTickEventHandler == null && disposed == false)
                 {
-                    _timerTickCallbackDelegate = (OnTick);
-                    TickSignal().Connect(_timerTickCallbackDelegate);
+                    TickSignal().Connect(_timerTickCallbackOfNative);
                 }
                 _timerTickEventHandler += value;
             }
@@ -124,7 +137,7 @@ namespace Tizen.NUI
                 _timerTickEventHandler -= value;
                 if (_timerTickEventHandler == null && TickSignal().Empty() == false)
                 {
-                    TickSignal().Disconnect(_timerTickCallbackDelegate);
+                    TickSignal().Disconnect(_timerTickCallbackOfNative);
                 }
             }
         }
@@ -135,7 +148,8 @@ namespace Tizen.NUI
 
             if (played == false)
             {
-                Tizen.Log.Fatal("NUI", $"({swigCPtr.Handle}) OnTick() is called even played is false!");
+                Tizen.Log.Fatal("NUI", $"(0x{swigCPtr.Handle:X}) OnTick() is called even played is false!");
+                //throw new System.InvalidOperationException($"OnTick() excpetion!");
             }
 
             if (_timerTickEventHandler != null && played == true)
@@ -156,7 +170,7 @@ namespace Tizen.NUI
         {
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
 
-            Tizen.Log.Error("NUI", $"({swigCPtr.Handle}) Timer({milliSec}) Constructor!");
+            NUILog.Debug($"(0x{swigCPtr.Handle:X})  Timer({milliSec}) Constructor!");
         }
         internal Timer(Timer timer) : this(NDalicPINVOKE.new_Timer__SWIG_1(Timer.getCPtr(timer)), true)
         {
@@ -214,8 +228,8 @@ namespace Tizen.NUI
         /// <param name="milliSec">MilliSec interval in milliseconds.</param>
         internal void SetInterval(uint milliSec)
         {
+            NUILog.Debug($"(0x{swigCPtr.Handle:X})SetInterval({milliSec})");
 
-            Tizen.Log.Error("NUI", $"({swigCPtr.Handle}) SetInterval({milliSec})");
             played = true;
 
             NDalicPINVOKE.Timer_SetInterval(swigCPtr, milliSec);
@@ -226,7 +240,6 @@ namespace Tizen.NUI
         {
             uint ret = NDalicPINVOKE.Timer_GetInterval(swigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            Tizen.Log.Error("NUI", $"({swigCPtr.Handle})GetInterval({ret})");
             return ret;
         }