[NUI] Do not register when BaseHandle doesn't have body
authorEunki, Hong <eunkiki.hong@samsung.com>
Thu, 2 Nov 2023 07:44:01 +0000 (16:44 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Mon, 6 Nov 2023 11:32:05 +0000 (20:32 +0900)
If BaseHandle doesn't have body, the refCPtr value is IntPtr.Zero.

If than, the various cases have wrong registration in future.

To avoid this case, let we ignore to register to registry, and
make BaseHandle.registerMe value as false.

Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
src/Tizen.NUI/src/internal/Common/Registry.cs
src/Tizen.NUI/src/public/Common/BaseHandle.cs

index d62fe6073abccf64628d719cbfad5158269b461f..7f9d0f1364cfc8847a9acc95c7cd555049fb7c95 100755 (executable)
@@ -51,11 +51,18 @@ namespace Tizen.NUI
         /// Stores the mapping between this instance of BaseHandle (C# base class) and native part.
         /// </summary>
         /// <param name="baseHandle">The instance of BaseHandle (C# base class).</param>
-        internal static void Register(BaseHandle baseHandle)
+        /// <returns>True if we success to register. False otherwise.</returns>
+        internal static bool Register(BaseHandle baseHandle)
         {
             // We store a pointer to the RefObject for the control
             IntPtr refCptr = Interop.BaseHandle.GetObjectPtr(baseHandle.GetBaseHandleCPtrHandleRef);
 
+            if (refCptr == IntPtr.Zero)
+            {
+                Tizen.Log.Error("NUI", $"We try to register BaseHandle dont have body! input type:{baseHandle.GetType()}\n");
+                return false;
+            }
+
             RegistryCurrentThreadCheck();
 
             if (Instance._controlMap.TryAdd(refCptr, new WeakReference(baseHandle, true)) != true)
@@ -69,7 +76,7 @@ namespace Tizen.NUI
 
                         // 2023-10-30 : Just print error log without exception. Please reopne below throw action after all apps fixed.
                         Tizen.Log.Fatal("NUI", "Error! just return here without Register! this can cause unknown error or crash in next step");
-                        return;
+                        return false;
                         //throw new System.InvalidOperationException("Error! NUI Registry weakReference should not be NULL!");
                     }
                     var target = weakReference.Target;
@@ -88,7 +95,7 @@ namespace Tizen.NUI
 
                             // 2023-10-30 : Just print error log without exception. Please reopne below throw action after all apps fixed.
                             Tizen.Log.Fatal("NUI", "Error! just return here without Register! this can cause unknown error or crash in next step");
-                            return;
+                            return false;
                             //throw new System.InvalidOperationException("refCptr register failed");
                         }
                     }
@@ -98,7 +105,7 @@ namespace Tizen.NUI
 
                         // 2023-10-30 : Just print error log without exception. Please reopne below throw action after all apps fixed.
                         Tizen.Log.Fatal("NUI", "Error! just return here without Register! this can cause unknown error or crash in next step");
-                        return;
+                        return false;
                         //throw new System.InvalidOperationException("refCptr is already exist!");
                     }
                 }
@@ -108,13 +115,13 @@ namespace Tizen.NUI
 
                     // 2023-10-30 : Just print error log without exception. Please reopne below throw action after all apps fixed.
                     Tizen.Log.Fatal("NUI", "Error! just return here without Register! this can cause unknown error or crash in next step");
-                    return;
+                    return false;
                     //throw new System.InvalidOperationException("refCptr is already exist, but fail to get handle!");
                 }
             }
 
             NUILog.Debug($"[Registry] Register! type:{baseHandle.GetType()} count:{Instance._controlMap.Count} copyNativeHandle:{baseHandle.GetBaseHandleCPtrHandleRef.Handle.ToString("X8")}");
-            return;
+            return true;
         }
 
         /// <summary>
index 2729cb9176c388329b2a9dd872bf28bb69be29b4..1bff524fcc88bfdfc3c0314db5db963736a25a93 100755 (executable)
@@ -91,7 +91,10 @@ namespace Tizen.NUI
             if (registerMe)
             {
                 // Register this instance of BaseHandle in the registry.
-                Registry.Register(this);
+                if (!Registry.Register(this))
+                {
+                    registerMe = false;
+                }
             }
 
             disposeDebuggingCtor();
@@ -113,7 +116,10 @@ namespace Tizen.NUI
             if (registerMe)
             {
                 // Register this instance of BaseHandle in the registry.
-                Registry.Register(this);
+                if (!Registry.Register(this))
+                {
+                    registerMe = false;
+                }
             }
 
             disposeDebuggingCtor();
@@ -133,7 +139,10 @@ namespace Tizen.NUI
             if (registerMe)
             {
                 // Register this instance of BaseHandle in the registry.
-                Registry.Register(this);
+                if (!Registry.Register(this))
+                {
+                    registerMe = false;
+                }
             }
 
             disposeDebuggingCtor();