From 8350e01c1eef7366c5fb97fa9b1cde4861619644 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 c1de491..377377e 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 @@ -56,10 +58,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 c4e380e..626c7f8 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewEvent.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewEvent.cs @@ -215,6 +215,7 @@ namespace Tizen.NUI.BaseComponents if (_onRelayoutEventHandler == null && OnRelayoutSignal().Empty() == false) { this.OnRelayoutSignal().Disconnect(_onRelayoutEventCallback); + _onRelayoutEventCallback = null; } } @@ -387,6 +388,7 @@ namespace Tizen.NUI.BaseComponents if (_onWindowEventHandler == null && OnWindowSignal().Empty() == false) { this.OnWindowSignal().Disconnect(_onWindowEventCallback); + _onWindowEventCallback = null; } } } @@ -416,6 +418,7 @@ namespace Tizen.NUI.BaseComponents if (_offWindowEventHandler == null && OffWindowSignal().Empty() == false) { this.OffWindowSignal().Disconnect(_offWindowEventCallback); + _offWindowEventCallback = null; } } } @@ -503,6 +506,7 @@ namespace Tizen.NUI.BaseComponents if (_resourcesLoadedEventHandler == null && ResourcesLoadedSignal().Empty() == false) { this.ResourcesLoadedSignal().Disconnect(_ResourcesLoadedCallback); + _ResourcesLoadedCallback = null; } } } @@ -558,6 +562,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 9df4a23..08f2c0e 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs @@ -1147,16 +1147,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) @@ -1187,6 +1190,7 @@ namespace Tizen.NUI.BaseComponents if (_ResourcesLoadedCallback != null) { this.ResourcesLoadedSignal().Disconnect(_ResourcesLoadedCallback); + _ResourcesLoadedCallback = null; } if (_keyCallback != null) @@ -1207,6 +1211,7 @@ namespace Tizen.NUI.BaseComponents if (_backgroundResourceLoadedCallback != null) { this.ResourcesLoadedSignal().Disconnect(_backgroundResourceLoadedCallback); + _backgroundResourceLoadedCallback = null; } if (_onWindowSendEventCallback != null) -- 2.7.4