From: Muhammad Umar Date: Fri, 18 Aug 2017 06:29:09 +0000 (+0900) Subject: [Tizen] DisConnect from Signals via using BaseHandleCPtr X-Git-Tag: accepted/tizen/4.0/unified/20170828.223314~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F68%2F145268%2F1;p=platform%2Fcore%2Fcsapi%2Fnui.git [Tizen] DisConnect from Signals via using BaseHandleCPtr There was a crash issue when disconnecting from signals from any class derived from View. This was due to the fact that the handle has been deleted earlier in derived class dispose function. Change-Id: Ib5c383b82dbd5ddab5010acdb82048fb27737df5 --- diff --git a/Tizen.NUI/src/public/BaseComponents/Scrollable.cs b/Tizen.NUI/src/public/BaseComponents/Scrollable.cs index 37f26bb..3803986 100755 --- a/Tizen.NUI/src/public/BaseComponents/Scrollable.cs +++ b/Tizen.NUI/src/public/BaseComponents/Scrollable.cs @@ -53,6 +53,29 @@ namespace Tizen.NUI.BaseComponents //You should not access any managed member here except static instance. //because the execution order of Finalizes is non-deterministic. + DisConnectFromSignals(); + + if (swigCPtr.Handle != global::System.IntPtr.Zero) + { + if (swigCMemOwn) + { + swigCMemOwn = false; + NDalicPINVOKE.delete_Scrollable(swigCPtr); + } + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + } + + base.Dispose(type); + } + + private void DisConnectFromSignals() + { + // Save current CPtr. + global::System.Runtime.InteropServices.HandleRef currentCPtr = swigCPtr; + + // Use BaseHandle CPtr as current might have been deleted already in derived classes. + swigCPtr = GetBaseHandleCPtrHandleRef; + if (_scrollableCompletedCallbackDelegate != null) { this.ScrollCompletedSignal().Disconnect(_scrollableCompletedCallbackDelegate); @@ -68,17 +91,9 @@ namespace Tizen.NUI.BaseComponents this.ScrollStartedSignal().Disconnect(_scrollableStartedCallbackDelegate); } - if (swigCPtr.Handle != global::System.IntPtr.Zero) - { - if (swigCMemOwn) - { - swigCMemOwn = false; - NDalicPINVOKE.delete_Scrollable(swigCPtr); - } - swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); - } - - base.Dispose(type); + // BaseHandle CPtr is used in Registry and there is danger of deletion if we keep using it here. + // Restore current CPtr. + swigCPtr = currentCPtr; } public class StartedEventArgs : EventArgs diff --git a/Tizen.NUI/src/public/BaseComponents/View.cs b/Tizen.NUI/src/public/BaseComponents/View.cs index 38fc529..87d76e8 100755 --- a/Tizen.NUI/src/public/BaseComponents/View.cs +++ b/Tizen.NUI/src/public/BaseComponents/View.cs @@ -140,6 +140,29 @@ namespace Tizen.NUI.BaseComponents //You should not access any managed member here except static instance. //because the execution order of Finalizes is non-deterministic. + DisConnectFromSignals(); + + if (swigCPtr.Handle != global::System.IntPtr.Zero) + { + if (swigCMemOwn) + { + swigCMemOwn = false; + NDalicPINVOKE.delete_View(swigCPtr); + } + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + } + + base.Dispose(type); + } + + private void DisConnectFromSignals() + { + // Save current CPtr. + global::System.Runtime.InteropServices.HandleRef currentCPtr = swigCPtr; + + // Use BaseHandle CPtr as current might have been deleted already in derived classes. + swigCPtr = GetBaseHandleCPtrHandleRef; + if (_onRelayoutEventCallback != null) { this.OnRelayoutSignal().Disconnect(_onRelayoutEventCallback); @@ -220,17 +243,9 @@ namespace Tizen.NUI.BaseComponents this.KeyInputFocusGainedSignal().Disconnect(_keyInputFocusGainedCallback); } - if (swigCPtr.Handle != global::System.IntPtr.Zero) - { - if (swigCMemOwn) - { - swigCMemOwn = false; - NDalicPINVOKE.delete_View(swigCPtr); - } - swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); - } - - base.Dispose(type); + // BaseHandle CPtr is used in Registry and there is danger of deletion if we keep using it here. + // Restore current CPtr. + swigCPtr = currentCPtr; } private EventHandler _keyInputFocusGainedEventHandler; diff --git a/Tizen.NUI/src/public/BaseHandle.cs b/Tizen.NUI/src/public/BaseHandle.cs index 4206215..40ed2a1 100755 --- a/Tizen.NUI/src/public/BaseHandle.cs +++ b/Tizen.NUI/src/public/BaseHandle.cs @@ -342,6 +342,14 @@ namespace Tizen.NUI return ret; } + internal global::System.Runtime.InteropServices.HandleRef GetBaseHandleCPtrHandleRef + { + get + { + return swigCPtr; + } + } + } } diff --git a/Tizen.NUI/src/public/UIComponents/Button.cs b/Tizen.NUI/src/public/UIComponents/Button.cs index 25b6182..43eb91a 100755 --- a/Tizen.NUI/src/public/UIComponents/Button.cs +++ b/Tizen.NUI/src/public/UIComponents/Button.cs @@ -72,6 +72,29 @@ namespace Tizen.NUI.UIComponents //You should not access any managed member here except static instance. //because the execution order of Finalizes is non-deterministic. + DisConnectFromSignals(); + + if (swigCPtr.Handle != global::System.IntPtr.Zero) + { + if (swigCMemOwn) + { + swigCMemOwn = false; + NDalicPINVOKE.delete_Button(swigCPtr); + } + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + } + + base.Dispose(type); + } + + private void DisConnectFromSignals() + { + // Save current CPtr. + global::System.Runtime.InteropServices.HandleRef currentCPtr = swigCPtr; + + // Use BaseHandle CPtr as current might have been deleted already in derived classes. + swigCPtr = GetBaseHandleCPtrHandleRef; + if (_stateChangedCallback != null) { StateChangedSignal().Disconnect(_stateChangedCallback); @@ -92,17 +115,9 @@ namespace Tizen.NUI.UIComponents ClickedSignal().Disconnect(_clickedCallback); } - if (swigCPtr.Handle != global::System.IntPtr.Zero) - { - if (swigCMemOwn) - { - swigCMemOwn = false; - NDalicPINVOKE.delete_Button(swigCPtr); - } - swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); - } - - base.Dispose(type); + // BaseHandle CPtr is used in Registry and there is danger of deletion if we keep using it here. + // Restore current CPtr. + swigCPtr = currentCPtr; }