[NUI] Fix test-hub crash issue
authordongsug.song <dongsug.song@samsung.com>
Sat, 19 Mar 2022 06:47:37 +0000 (15:47 +0900)
committerSangHyeon Jade Lee <dltkdgus1764@gmail.com>
Mon, 21 Mar 2022 04:42:42 +0000 (13:42 +0900)
src/Tizen.NUI/src/internal/Common/DebugFileLogging.cs
src/Tizen.NUI/src/internal/Common/Disposable.cs
src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs
src/Tizen.NUI/src/public/Common/BaseHandle.cs

index 7183da4..c119d44 100755 (executable)
@@ -22,10 +22,10 @@ using global::System.Diagnostics;
 
 namespace Tizen.NUI
 {
-    internal class DebugFileLogging
+    internal class DebugFileLogging : Disposable
     {
         #region Constant Fields
-        private const string logFolderPath = "/home/ssong2best/Downloads/0128/";//"/run/user/5001/nui/"; //need fix as for target (tv, ubuntu, and etc)
+        private string logFolderPath;
         #endregion //Constant Fields
 
         #region Fields
@@ -38,6 +38,15 @@ namespace Tizen.NUI
         #region Constructors
         private DebugFileLogging()
         {
+            if (Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX)
+            {
+                logFolderPath = Environment.GetEnvironmentVariable("HOME") + "/nui/";
+            }
+            else
+            {
+                logFolderPath = Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%") + "/owner/share/nui/";
+            }
+
             Directory.CreateDirectory(logFolderPath);
 
             var id = Process.GetCurrentProcess().Id;
index 9388d9a..24a29b1 100644 (file)
@@ -113,14 +113,20 @@ namespace Tizen.NUI
                     var thread = global::System.Threading.Thread.CurrentThread.ManagedThreadId;
                     var me = this.GetType().FullName;
 
-                    throw new global::System.InvalidOperationException("[NUI][Disposable]This API called from separate thread. This API must be called from MainThread. \n" +
+                    Tizen.Log.Fatal("NUI", $"[NUI][Disposable]This API called from separate thread. This API must be called from MainThread. \n" +
                         $" process:{process} thread:{thread}, disposing:{disposing}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me}\n");
+
+                    //to fix ArtApp black screen issue. this will be enabled after talking with ArtApp team and fixing it.
+                    // throw new global::System.InvalidOperationException("[NUI][Disposable]This API called from separate thread. This API must be called from MainThread. \n" +
+                    //     $" process:{process} thread:{thread}, disposing:{disposing}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me}\n");
                 }
 
                 if (isDisposeQueued)
                 {
                     Tizen.Log.Fatal("NUI", $"[Disposable]should not be here! (dead code) this will be removed!");
-                    throw new global::System.Exception($"[NUI] should not be here! (dead code) this will be removed!");
+
+                    //to fix ArtApp black screen issue. this will be enabled after talking with ArtApp team and fixing it.
+                    // throw new global::System.Exception($"[NUI] should not be here! (dead code) this will be removed!");
                     Dispose(DisposeTypes.Implicit);
                 }
                 else
index 4f61176..db7ef06 100755 (executable)
@@ -17,6 +17,7 @@
 
 using System;
 using System.ComponentModel;
+using global::System.Diagnostics;
 
 namespace Tizen.NUI.BaseComponents
 {
@@ -1078,12 +1079,12 @@ namespace Tizen.NUI.BaseComponents
 
             // ActionUpdateProperty works well only if BACKGROUND visual setup before.
             // If view don't have BACKGROUND visual, we set transparent background color in default.
-            using(PropertyMap backgroundPropertyMap = new PropertyMap())
+            using (PropertyMap backgroundPropertyMap = new PropertyMap())
             {
-                using(PropertyValue propertyValue = Object.GetProperty(SwigCPtr, Property.BACKGROUND))
+                using (PropertyValue propertyValue = Object.GetProperty(SwigCPtr, Property.BACKGROUND))
                 {
                     propertyValue?.Get(backgroundPropertyMap);
-                    if(backgroundPropertyMap.Empty())
+                    if (backgroundPropertyMap.Empty())
                     {
                         // BACKGROUND visual doesn't exist.
                         SetBackgroundColor(Color.Transparent);
@@ -1154,16 +1155,7 @@ namespace Tizen.NUI.BaseComponents
                 return;
             }
 
-            DebugFileLogging.Instance.WriteLog($"View.Dispose({type}) START");
-            DebugFileLogging.Instance.WriteLog($"type:{GetType()} copyNativeHandle:{GetBaseHandleCPtrHandleRef.Handle.ToString("X8")}");
-            if(HasBody())
-            {
-                DebugFileLogging.Instance.WriteLog($"ID:{Interop.Actor.GetId(GetBaseHandleCPtrHandleRef)} Name:{Interop.Actor.GetName(GetBaseHandleCPtrHandleRef)}");
-            }
-            else
-            {
-                DebugFileLogging.Instance.WriteLog($"has no native body!");
-            }
+            disposeDebugging(type);
 
             //_mergedStyle = null;
 
@@ -1526,5 +1518,21 @@ namespace Tizen.NUI.BaseComponents
 
             return themeData.selectorData ?? (themeData.selectorData = new ViewSelectorData());
         }
+
+        [Conditional("NUI_DEBUG_ON")]
+        private void disposeDebugging(DisposeTypes type)
+        {
+            DebugFileLogging.Instance.WriteLog($"View.Dispose({type}) START");
+            DebugFileLogging.Instance.WriteLog($"type:{GetType()} copyNativeHandle:{GetBaseHandleCPtrHandleRef.Handle.ToString("X8")}");
+            if (HasBody())
+            {
+                DebugFileLogging.Instance.WriteLog($"ID:{Interop.Actor.GetId(GetBaseHandleCPtrHandleRef)} Name:{Interop.Actor.GetName(GetBaseHandleCPtrHandleRef)}");
+            }
+            else
+            {
+                DebugFileLogging.Instance.WriteLog($"has no native body!");
+            }
+        }
+
     }
 }
index b50fd7f..d914773 100755 (executable)
@@ -18,6 +18,7 @@ using System;
 using System.ComponentModel;
 using System.Runtime.CompilerServices;
 using Tizen.NUI.Binding;
+using global::System.Diagnostics;
 
 namespace Tizen.NUI
 {
@@ -88,11 +89,7 @@ namespace Tizen.NUI
                 Registry.Register(this);
             }
 
-            DebugFileLogging.Instance.WriteLog($"type:{GetType()} copyNativeHandle:{swigCPtrCopy.Handle.ToString("X8")}");
-            if (this is BaseComponents.View view)
-            {
-                  DebugFileLogging.Instance.WriteLog($"ID:{view.ID} Name:{view.Name}");
-            }
+            disposeDebuggingCtor();
             DebugFileLogging.Instance.WriteLog($" BaseHandle.contructor with cMemeryOwn END");
             DebugFileLogging.Instance.WriteLog($"=============================");
         }
@@ -115,11 +112,7 @@ namespace Tizen.NUI
                 Registry.Register(this);
             }
 
-            DebugFileLogging.Instance.WriteLog($"type:{GetType()} copyNativeHandle:{swigCPtrCopy.Handle.ToString("X8")}");
-            if (this is BaseComponents.View view)
-            {
-                DebugFileLogging.Instance.WriteLog($"ID:{view.ID} Name:{view.Name}");
-            }
+            disposeDebuggingCtor();
             DebugFileLogging.Instance.WriteLog($"BaseHandle.contructor END");
             DebugFileLogging.Instance.WriteLog($"=============================");
         }
@@ -356,15 +349,22 @@ namespace Tizen.NUI
                     DebugFileLogging.Instance.WriteLog("[NUI][BaseHandle] This API called from separate thread. This API must be called from MainThread. \n" +
                         $" process:{process} thread:{thread}, disposing:{disposing}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me}\n");
 
-                    throw new global::System.InvalidOperationException("[NUI][BaseHandle] This API called from separate thread. This API must be called from MainThread. \n" +
+                    Tizen.Log.Fatal("NUI", $"[NUI][BaseHandle] This API called from separate thread. This API must be called from MainThread. \n" +
                         $" process:{process} thread:{thread}, disposing:{disposing}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me}\n");
+
+                    //to fix ArtApp black screen issue. this will be enabled after talking with ArtApp team and fixing it.
+                    // throw new global::System.InvalidOperationException("[NUI][BaseHandle] This API called from separate thread. This API must be called from MainThread. \n" +
+                    //     $" process:{process} thread:{thread}, disposing:{disposing}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me}\n");
                 }
 
                 if (isDisposeQueued)
                 {
                     DebugFileLogging.Instance.WriteLog($"should not be here! (dead code) this will be removed!");
 
-                    throw new global::System.Exception($"[NUI] should not be here! (dead code) this will be removed!");
+                    Tizen.Log.Fatal("NUI", $"[NUI] should not be here! (dead code) this will be removed!");
+
+                    //to fix ArtApp black screen issue. this will be enabled after talking with ArtApp team and fixing it.
+                    // throw new global::System.Exception($"[NUI] should not be here! (dead code) this will be removed!");
                     Dispose(DisposeTypes.Implicit);
                 }
                 else
@@ -544,39 +544,7 @@ namespace Tizen.NUI
                 Registry.Unregister(this);
             }
 
-            DebugFileLogging.Instance.WriteLog($"swigCMemOwn:{swigCMemOwn} type:{GetType()} copyNativeHandle:{swigCPtrCopy.Handle.ToString("X8")}");
-
-            // this is temporary test code. will be removed laster
-            {
-                if (swigCPtr.Handle != IntPtr.Zero && swigCPtrCopy.Handle != IntPtr.Zero)
-                {
-                    var process = global::System.Diagnostics.Process.GetCurrentProcess().Id;
-                    var thread = global::System.Threading.Thread.CurrentThread.ManagedThreadId;
-                    var me = this.GetType().FullName;
-                    var daliId = "unknown";
-                    var hash = this.GetType().GetHashCode();
-                    var name = "unknown";
-
-                    if (this is BaseComponents.View)
-                    {
-                        daliId = Interop.Actor.GetId(swigCPtrCopy).ToString();
-                        name = Interop.Actor.GetName(swigCPtrCopy);
-                        BaseObject tmp = new BaseObject(Interop.BaseHandle.GetBaseObject(swigCPtrCopy), false);
-                        var refCnt = tmp.ReferenceCount();
-                        tmp.Dispose();
-                        if (refCnt > 2)
-                        {
-                            DebugFileLogging.Instance.WriteLog($"[ERR] reference count is over than 2. Could be a memory leak. Need to check! \n" +
-                                $" process:{process} thread:{thread}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me} \n" +
-                                $" disposeType:{type}, name:{name}, daliID:{daliId}, hash:{hash}, refCnt:{refCnt}");
-
-                            Log.Error("NUI", $"[ERR] reference count is over than 2. Could be a memory leak. Need to check! \n" +
-                                $" process:{process} thread:{thread}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me} \n" +
-                                $" disposeType:{type}, name:{name}, daliID:{daliId}, hash:{hash}, refCnt:{refCnt}");
-                        }
-                    }
-                }
-            }
+            disposeDebuggingDispose(type);
 
             if (SwigCPtr.Handle != IntPtr.Zero)
             {
@@ -652,9 +620,14 @@ namespace Tizen.NUI
                     var thread = global::System.Threading.Thread.CurrentThread.ManagedThreadId;
                     var me = this.GetType().FullName;
 
-                    throw new ObjectDisposedException(nameof(SwigCPtr), $"Error! NUI's native dali object is already disposed. " +
+                    Tizen.Log.Fatal("NUI", $"SwigCPtr Error! NUI's native dali object is already disposed. " +
                         $"OR the native dali object handle of NUI becomes null! \n" +
                         $" process:{process} thread:{thread}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me}\n");
+
+                    //to fix ArtApp black screen issue. this will be enabled after talking with ArtApp team and fixing it.
+                    // throw new ObjectDisposedException(nameof(SwigCPtr), $"Error! NUI's native dali object is already disposed. " +
+                    //     $"OR the native dali object handle of NUI becomes null! \n" +
+                    //     $" process:{process} thread:{thread}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me}\n");
                 }
                 return swigCPtr;
             }
@@ -683,5 +656,57 @@ namespace Tizen.NUI
         [EditorBrowsable(EditorBrowsableState.Never)]
         protected internal bool IsDisposeQueued => isDisposeQueued;
 
+        [Conditional("NUI_DEBUG_ON")]
+        private void disposeDebuggingCtor()
+        {
+            DebugFileLogging.Instance.WriteLog($"type:{GetType()} copyNativeHandle:{swigCPtrCopy.Handle.ToString("X8")}");
+            if (this is BaseComponents.View view)
+            {
+                DebugFileLogging.Instance.WriteLog($"ID:{view.ID} Name:{view.Name}");
+                //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);
+                    DebugFileLogging.Instance.WriteLog($"[{i}] {sf.GetMethod()}");
+                }
+            }
+        }
+
+        [Conditional("NUI_DEBUG_ON")]
+        private void disposeDebuggingDispose(DisposeTypes type)
+        {
+            DebugFileLogging.Instance.WriteLog($"swigCMemOwn:{swigCMemOwn} type:{GetType()} copyNativeHandle:{swigCPtrCopy.Handle.ToString("X8")} HasBody:{HasBody()}");
+
+            if (swigCPtr.Handle != IntPtr.Zero && swigCPtrCopy.Handle != IntPtr.Zero && HasBody())
+            {
+                var process = global::System.Diagnostics.Process.GetCurrentProcess().Id;
+                var thread = global::System.Threading.Thread.CurrentThread.ManagedThreadId;
+                var me = this.GetType().FullName;
+                var daliId = "unknown";
+                var hash = this.GetType().GetHashCode();
+                var name = "unknown";
+
+                if (this is BaseComponents.View)
+                {
+                    daliId = Interop.Actor.GetId(swigCPtrCopy).ToString();
+                    name = Interop.Actor.GetName(swigCPtrCopy);
+                    BaseObject tmp = new BaseObject(Interop.BaseHandle.GetBaseObject(swigCPtrCopy), false);
+                    var refCnt = tmp.ReferenceCount();
+                    tmp.Dispose();
+                    if (refCnt > 2)
+                    {
+                        DebugFileLogging.Instance.WriteLog($"[ERR] reference count is over than 2. Could be a memory leak. Need to check! \n" +
+                            $" process:{process} thread:{thread}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me} \n" +
+                            $" disposeType:{type}, name:{name}, daliID:{daliId}, hash:{hash}, refCnt:{refCnt}");
+
+                        Log.Error("NUI", $"[ERR] reference count is over than 2. Could be a memory leak. Need to check! \n" +
+                            $" process:{process} thread:{thread}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me} \n" +
+                            $" disposeType:{type}, name:{name}, daliID:{daliId}, hash:{hash}, refCnt:{refCnt}");
+                    }
+                }
+            }
+        }
+
     }
 }