From: dongsug.song Date: Thu, 14 Dec 2017 06:35:29 +0000 (+0900) Subject: [4.0] add depense code for TriggerEvent callback null reference issue X-Git-Tag: 4.0.1-preview1-00042~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f71e170340660df96ebee7dc6bed84dd7ad1d040;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [4.0] add depense code for TriggerEvent callback null reference issue Change-Id: If2576f22ba10cf23cc0724df4ccf2513a68c30e1 Signed-off-by: dongsug.song --- diff --git a/src/Tizen.NUI/src/internal/Application.cs b/src/Tizen.NUI/src/internal/Application.cs index b6174b0..1378245 100755 --- a/src/Tizen.NUI/src/internal/Application.cs +++ b/src/Tizen.NUI/src/internal/Application.cs @@ -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(); } /** diff --git a/src/Tizen.NUI/src/internal/TimerSignalType.cs b/src/Tizen.NUI/src/internal/TimerSignalType.cs index fda4dd7..aae2fa5 100755 --- a/src/Tizen.NUI/src/internal/TimerSignalType.cs +++ b/src/Tizen.NUI/src/internal/TimerSignalType.cs @@ -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); diff --git a/src/Tizen.NUI/src/public/Timer.cs b/src/Tizen.NUI/src/public/Timer.cs index 4d095c1..3ca9ff4 100755 --- a/src/Tizen.NUI/src/public/Timer.cs +++ b/src/Tizen.NUI/src/public/Timer.cs @@ -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(_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 /// 3 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 _timerTickEventHandler; private TickCallbackDelegate _timerTickCallbackDelegate; + private System.IntPtr _timerTickCallbackOfNative; + /// /// @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.
@@ -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 /// MilliSec interval in milliseconds. 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; }