[NUI] Fix Window.Instance null issue
authorhuiyu.eun <huiyu.eun@samsung.com>
Wed, 7 Apr 2021 01:38:18 +0000 (10:38 +0900)
committerhuiyueun <35286162+huiyueun@users.noreply.github.com>
Tue, 20 Apr 2021 06:13:00 +0000 (15:13 +0900)
If call Window.Instance before initializing, Window.Instance is always null

Signed-off-by: huiyu.eun <huiyu.eun@samsung.com>
src/Tizen.NUI/src/internal/Application/Application.cs
src/Tizen.NUI/src/public/Window/Window.cs

index 13f7aab..ab46101 100755 (executable)
@@ -490,8 +490,8 @@ namespace Tizen.NUI
                 appControlSignal = null;
             }
 
-            win?.Dispose();
-            win = null;
+            window?.Dispose();
+            window = null;
 
             base.Dispose(type);
         }
@@ -575,7 +575,7 @@ namespace Tizen.NUI
         private NUIApplicationAppControlEventCallbackDelegate applicationAppControlEventCallbackDelegate;
         private ApplicationControlSignal appControlSignal;
 
-        private Window win;
+        private Window window;
 
         /**
           * @brief Event for Initialized signal which can be used to subscribe/unsubscribe the event handler
@@ -613,6 +613,7 @@ namespace Tizen.NUI
         {
             // Initialize DisposeQueue Singleton class. This is also required to create DisposeQueue on main thread.
             DisposeQueue.Instance.Initialize();
+            Window.Instance = GetWindow();
 
             // Notify that the window is displayed to the app core.
             if (NUIApplication.IsPreload)
@@ -1259,14 +1260,15 @@ namespace Tizen.NUI
 
         public Window GetWindow()
         {
-            win = Registry.GetManagedBaseHandleFromNativePtr(Interop.Application.GetWindow(SwigCPtr)) as Window;
-            if (win == null)
+            if (window != null)
             {
-                win = new Window(Interop.Application.GetWindow(SwigCPtr), true);
+                return window;
             }
 
+            window = (Registry.GetManagedBaseHandleFromNativePtr(Interop.Application.GetWindow(SwigCPtr)) as Window) ?? new Window(Interop.Application.GetWindow(SwigCPtr), true);
+
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            return win;
+            return window;
         }
 
         public static string GetResourcePath()
index 2738663..db7bcaa 100755 (executable)
@@ -34,8 +34,6 @@ namespace Tizen.NUI
     /// <since_tizen> 3 </since_tizen>
     public partial class Window : BaseHandle
     {
-        private static readonly Window instance = Application.Instance?.GetWindow();
-
         private HandleRef stageCPtr;
         private Layer rootLayer;
         private string windowTitle;
@@ -264,13 +262,7 @@ namespace Tizen.NUI
         /// Gets the current window.<br />
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
-        public static Window Instance
-        {
-            get
-            {
-                return instance;
-            }
-        }
+        public static Window Instance { get; internal set; }
 
         /// <summary>
         /// Gets or sets a window type.