[Tizen] DisConnect from Signals via using BaseHandleCPtr 68/145268/1
authorMuhammad Umar <m.umar@partner.samsung.com>
Fri, 18 Aug 2017 06:29:09 +0000 (15:29 +0900)
committerdongsug.song <dongsug.song@samsung.com>
Tue, 22 Aug 2017 02:27:02 +0000 (11:27 +0900)
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

Tizen.NUI/src/public/BaseComponents/Scrollable.cs
Tizen.NUI/src/public/BaseComponents/View.cs
Tizen.NUI/src/public/BaseHandle.cs
Tizen.NUI/src/public/UIComponents/Button.cs

index 37f26bb..3803986 100755 (executable)
@@ -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
index 38fc529..87d76e8 100755 (executable)
@@ -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;
index 4206215..40ed2a1 100755 (executable)
@@ -342,6 +342,14 @@ namespace Tizen.NUI
             return ret;
         }
 
+        internal global::System.Runtime.InteropServices.HandleRef GetBaseHandleCPtrHandleRef
+        {
+            get
+            {
+                return swigCPtr;
+            }
+        }
+
     }
 
 }
index 25b6182..43eb91a 100755 (executable)
@@ -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;
         }