From e70f4a26c1fe62a4cf20e724ca4aa551773d564b Mon Sep 17 00:00:00 2001 From: Dongsug Song Date: Mon, 5 Oct 2020 19:38:58 +0900 Subject: [PATCH] [NUI] Add defensive code for ViewSignal Disconnect() --- src/Tizen.NUI/src/internal/ViewSignal.cs | 23 +++++++++++++++++++--- .../src/public/BaseComponents/ViewEvent.cs | 5 +++++ .../src/public/BaseComponents/ViewInternal.cs | 5 +++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/Tizen.NUI/src/internal/ViewSignal.cs b/src/Tizen.NUI/src/internal/ViewSignal.cs index 5648405..bbe2ca1 100755 --- a/src/Tizen.NUI/src/internal/ViewSignal.cs +++ b/src/Tizen.NUI/src/internal/ViewSignal.cs @@ -14,6 +14,8 @@ * limitations under the License. * */ + +using global::System.Threading; using Tizen.NUI.BaseComponents; namespace Tizen.NUI @@ -83,10 +85,25 @@ namespace Tizen.NUI public void Disconnect(System.Delegate func) { - System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(func); + try { - Interop.ActorSignal.ActorSignal_Disconnect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip)); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(func); + { + Interop.ActorSignal.ActorSignal_Disconnect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip)); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + } + catch (global::System.Exception ex) + { + Tizen.Log.Fatal("NUI", $"[ERROR] excpetion! {ex}: {ex.Message}"); + Tizen.Log.Fatal("NUI", $"[ERROR] current threadID : {Thread.CurrentThread.ManagedThreadId}"); + Tizen.Log.Fatal("NUI", $"[ERROR] back trace!"); + global::System.Diagnostics.StackTrace st = new global::System.Diagnostics.StackTrace(true); + for (int i = 0; i < st.FrameCount; i++) + { + global::System.Diagnostics.StackFrame sf = st.GetFrame(i); + Tizen.Log.Fatal("NUI", " Method " + sf.GetMethod()); + } } } diff --git a/src/Tizen.NUI/src/public/BaseComponents/ViewEvent.cs b/src/Tizen.NUI/src/public/BaseComponents/ViewEvent.cs index 4cd9f5f..da88f71 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewEvent.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewEvent.cs @@ -211,6 +211,7 @@ namespace Tizen.NUI.BaseComponents if (_onRelayoutEventHandler == null && OnRelayoutSignal().Empty() == false) { this.OnRelayoutSignal().Disconnect(_onRelayoutEventCallback); + _onRelayoutEventCallback = null; } } @@ -331,6 +332,7 @@ namespace Tizen.NUI.BaseComponents if (_onWindowEventHandler == null && OnWindowSignal().Empty() == false) { this.OnWindowSignal().Disconnect(_onWindowEventCallback); + _onWindowEventCallback = null; } } } @@ -360,6 +362,7 @@ namespace Tizen.NUI.BaseComponents if (_offWindowEventHandler == null && OffWindowSignal().Empty() == false) { this.OffWindowSignal().Disconnect(_offWindowEventCallback); + _offWindowEventCallback = null; } } } @@ -447,6 +450,7 @@ namespace Tizen.NUI.BaseComponents if (_resourcesLoadedEventHandler == null && ResourcesLoadedSignal().Empty() == false) { this.ResourcesLoadedSignal().Disconnect(_ResourcesLoadedCallback); + _ResourcesLoadedCallback = null; } } } @@ -470,6 +474,7 @@ namespace Tizen.NUI.BaseComponents if (_backgroundResourceLoadedEventHandler == null && ResourcesLoadedSignal().Empty() == false) { this.ResourcesLoadedSignal().Disconnect(_backgroundResourceLoadedCallback); + _backgroundResourceLoadedCallback = null; } } } diff --git a/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs b/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs index 6d6d632..dd801ba 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs @@ -1061,16 +1061,19 @@ namespace Tizen.NUI.BaseComponents if (_onRelayoutEventCallback != null) { this.OnRelayoutSignal().Disconnect(_onRelayoutEventCallback); + _onRelayoutEventCallback = null; } if (_offWindowEventCallback != null) { this.OffWindowSignal().Disconnect(_offWindowEventCallback); + _offWindowEventCallback = null; } if (_onWindowEventCallback != null) { this.OnWindowSignal().Disconnect(_onWindowEventCallback); + _onWindowEventCallback = null; } if (_wheelEventCallback != null) @@ -1091,6 +1094,7 @@ namespace Tizen.NUI.BaseComponents if (_ResourcesLoadedCallback != null) { this.ResourcesLoadedSignal().Disconnect(_ResourcesLoadedCallback); + _ResourcesLoadedCallback = null; } if (_offWindowEventCallback != null) @@ -1141,6 +1145,7 @@ namespace Tizen.NUI.BaseComponents if (_backgroundResourceLoadedCallback != null) { this.ResourcesLoadedSignal().Disconnect(_backgroundResourceLoadedCallback); + _backgroundResourceLoadedCallback = null; } if (_onWindowSendEventCallback != null) -- 2.7.4