2729cb9176c388329b2a9dd872bf28bb69be29b4
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Common / BaseHandle.cs
1 /*
2  * Copyright(c) 2022 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 using System;
18 using System.ComponentModel;
19 using System.Runtime.CompilerServices;
20 using Tizen.NUI.Binding;
21 using global::System.Diagnostics;
22
23 namespace Tizen.NUI
24 {
25     /// <summary>
26     /// BaseHandle is a handle to an internal Dali resource.
27     /// </summary>
28     /// <since_tizen> 3 </since_tizen>
29     public class BaseHandle : Element, global::System.IDisposable
30     {
31         static internal void Preload()
32         {
33             // Do nothing. Just call for load static values.
34         }
35
36         /// <summary>
37         /// swigCMemOwn
38         /// </summary>
39         /// <since_tizen> 3 </since_tizen>
40         [Obsolete("Deprecated in API9, will be removed in API11, Use SwigCMemOwn")]
41         [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "<Pending>")]
42         protected bool swigCMemOwn;
43
44         /// <summary>
45         /// The flag to check if it is already disposed of.
46         /// </summary>
47         /// <since_tizen> 3 </since_tizen>
48         [Obsolete("Deprecated in API9, will be removed in API11, Use Disposed")]
49         [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "<Pending>")]
50         protected bool disposed = false;
51
52         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
53         private bool registerMe;
54
55         //The flag to check who called Dispose(). (By User or DisposeQueue)
56         private bool isDisposeQueued = false;
57
58         /// <summary>
59         /// Create an instance of BaseHandle.
60         /// </summary>
61         /// <since_tizen> 3 </since_tizen>
62         public BaseHandle() : this(Interop.BaseHandle.NewBaseHandle(), true, false)
63         {
64             // Note : Empty BaseHandle instance don't need to be register in Registry.
65             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
66         }
67
68         /// <summary>
69         /// Create an instance of BaseHandle.
70         /// </summary>
71         /// <param name="handle">The BaseHandle instance.</param>
72         /// <since_tizen> 3 </since_tizen>
73         public BaseHandle(BaseHandle handle) : this(Interop.BaseHandle.NewBaseHandle(BaseHandle.getCPtr(handle)), true, false)
74         {
75             // Note : Copyed BaseHandle instance don't need to be register in Registry.
76             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
77         }
78
79         internal BaseHandle(global::System.IntPtr cPtr, bool cMemoryOwn, bool cRegister)
80         {
81             //to catch derived classes dali native exceptions
82             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
83
84             DebugFileLogging.Instance.WriteLog($"BaseHandle.contructor with cMemeryOwn:{cMemoryOwn} and cRegister:{cRegister} START");
85
86             registerMe = cRegister;
87             swigCMemOwn = cMemoryOwn;
88             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
89             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
90
91             if (registerMe)
92             {
93                 // Register this instance of BaseHandle in the registry.
94                 Registry.Register(this);
95             }
96
97             disposeDebuggingCtor();
98             DebugFileLogging.Instance.WriteLog($" BaseHandle.contructor with cMemeryOwn and cRegister END");
99             DebugFileLogging.Instance.WriteLog($"=============================");
100         }
101
102         internal BaseHandle(global::System.IntPtr cPtr, bool cMemoryOwn)
103         {
104             //to catch derived classes dali native exceptions
105             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
106
107             DebugFileLogging.Instance.WriteLog($"BaseHandle.contructor with cMemeryOwn:{cMemoryOwn} START");
108
109             registerMe = swigCMemOwn = cMemoryOwn;
110             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
111             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
112
113             if (registerMe)
114             {
115                 // Register this instance of BaseHandle in the registry.
116                 Registry.Register(this);
117             }
118
119             disposeDebuggingCtor();
120             DebugFileLogging.Instance.WriteLog($" BaseHandle.contructor with cMemeryOwn END");
121             DebugFileLogging.Instance.WriteLog($"=============================");
122         }
123
124         internal BaseHandle(global::System.IntPtr cPtr)
125         {
126             DebugFileLogging.Instance.WriteLog($"BaseHandle.contructor START");
127
128             registerMe = swigCMemOwn = true;
129
130             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
131             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
132
133             if (registerMe)
134             {
135                 // Register this instance of BaseHandle in the registry.
136                 Registry.Register(this);
137             }
138
139             disposeDebuggingCtor();
140             DebugFileLogging.Instance.WriteLog($"BaseHandle.contructor END");
141             DebugFileLogging.Instance.WriteLog($"=============================");
142         }
143
144         /// <summary>
145         /// Dispose.
146         /// </summary>
147         /// <since_tizen> 3 </since_tizen>
148         // following this guide: https://docs.microsoft.com/ko-kr/dotnet/fundamentals/code-analysis/quality-rules/ca1063?view=vs-2019 (CA1063)
149         ~BaseHandle() => Dispose(false);
150
151         /// <summary>
152         /// Event when a property is set.
153         /// </summary>
154         /// <since_tizen> 5 </since_tizen>
155         /// <seealso cref="BindableObject.PropertyChanged"/>
156         [Obsolete("Deprecated in API9, will be removed in API11, Use BindableObject.PropertyChanged instead.")]
157         public event PropertyChangedEventHandler PropertySet;
158
159         internal global::System.Runtime.InteropServices.HandleRef GetBaseHandleCPtrHandleRef
160         {
161             get
162             {
163                 return swigCPtr;
164             }
165         }
166
167         /// <summary>
168         /// Returns the bool value true to indicate that an operand is true and returns false otherwise.
169         /// </summary>
170         /// <since_tizen> 3 </since_tizen>
171         public static bool operator true(BaseHandle handle)
172         {
173             // if the C# object is null, return false
174             if (BaseHandle.ReferenceEquals(handle, null))
175             {
176                 return false;
177             }
178             // returns true if the handle has a body, false otherwise
179             return handle.HasBody();
180         }
181
182         /// <summary>
183         /// Returns the bool false  to indicate that an operand is false and returns true otherwise.
184         /// </summary>
185         /// <since_tizen> 3 </since_tizen>
186         public static bool operator false(BaseHandle handle)
187         {
188             // if the C# object is null, return true
189             if (BaseHandle.ReferenceEquals(handle, null))
190             {
191                 return true;
192             }
193             return !handle.HasBody();
194         }
195
196         /// <summary>
197         /// Explicit conversion from Handle to bool.
198         /// </summary>
199         /// <since_tizen> 3 </since_tizen>
200         public static explicit operator bool(BaseHandle handle)
201         {
202             // if the C# object is null, return false
203             if (BaseHandle.ReferenceEquals(handle, null))
204             {
205                 return false;
206             }
207             // returns true if the handle has a body, false otherwise
208             return handle.HasBody();
209         }
210
211         /// <summary>
212         /// Equality operator
213         /// </summary>
214         /// <since_tizen> 3 </since_tizen>
215         public static bool operator ==(BaseHandle x, BaseHandle y)
216         {
217             // if the C# objects are the same return true
218             if (BaseHandle.ReferenceEquals(x, y))
219             {
220                 return true;
221             }
222             if (!BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
223             {
224                 // drop into native code to see if both handles point to the same body
225                 return x.IsEqual(y);
226             }
227
228             if (BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
229             {
230                 if (y.HasBody()) return false;
231                 else return true;
232             }
233             if (!BaseHandle.ReferenceEquals(x, null) && BaseHandle.ReferenceEquals(y, null))
234             {
235                 if (x.HasBody()) return false;
236                 else return true;
237             }
238
239             return false;
240         }
241
242         /// <summary>
243         /// Inequality operator. Returns Null if either operand is Null
244         /// </summary>
245         /// <since_tizen> 3 </since_tizen>
246         public static bool operator !=(BaseHandle x, BaseHandle y)
247         {
248             return !(x == y);
249         }
250
251         /// <summary>
252         /// Logical AND operator.<br />
253         /// It's possible when doing a  operator this function (opBitwiseAnd) is never called due to short circuiting.<br />
254         /// </summary>
255         /// <since_tizen> 3 </since_tizen>
256         public static BaseHandle operator &(BaseHandle x, BaseHandle y)
257         {
258             if (x == y)
259             {
260                 return x;
261             }
262             return null;
263         }
264
265         /// <summary>
266         /// Logical OR operator for ||.<br />
267         /// It's possible when doing a || this function (opBitwiseOr) is never called due to short circuiting.<br />
268         /// </summary>
269         /// <since_tizen> 3 </since_tizen>
270         public static BaseHandle operator |(BaseHandle x, BaseHandle y)
271         {
272             if (!BaseHandle.ReferenceEquals(x, null) || !BaseHandle.ReferenceEquals(y, null))
273             {
274                 if (x != null && x.HasBody())
275                 {
276                     return x;
277                 }
278                 if (y != null && y.HasBody())
279                 {
280                     return y;
281                 }
282                 return null;
283             }
284             return null;
285         }
286
287         /// <summary>
288         /// Logical ! operator
289         /// </summary>
290         /// <since_tizen> 3 </since_tizen>
291         public static bool operator !(BaseHandle x)
292         {
293             // if the C# object is null, return true
294             if (BaseHandle.ReferenceEquals(x, null))
295             {
296                 return true;
297             }
298             if (x.HasBody())
299             {
300                 return false;
301             }
302             return true;
303         }
304
305         /// <summary>
306         /// Equals
307         /// </summary>
308         /// <param name="o">The object should be compared.</param>
309         /// <returns>True if equal.</returns>
310         /// <since_tizen> 5 </since_tizen>
311         public override bool Equals(object o)
312         {
313             return base.Equals(o);
314         }
315
316         /// <summary>
317         /// Gets the hash code of this baseHandle.
318         /// </summary>
319         /// <returns>The hash code.</returns>
320         /// <since_tizen> 5 </since_tizen>
321         public override int GetHashCode()
322         {
323             return base.GetHashCode();
324         }
325
326         /// <summary>
327         /// Dispose.
328         /// </summary>
329         /// <since_tizen> 3 </since_tizen>
330         public void Dispose()
331         {
332             if (isDisposeQueued)
333             {
334                 Dispose(DisposeTypes.Implicit);
335             }
336             else
337             {
338                 Dispose(true);
339             }
340             GC.SuppressFinalize(this);
341         }
342
343         /// <summary>
344         /// Hidden API (Inhouse API).
345         /// Dispose. 
346         /// </summary>
347         /// <remarks>
348         /// Following the guide of https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-dispose.
349         /// This will replace "protected virtual void Dispose(DisposeTypes type)" which is exactly same in functionality.
350         /// </remarks>
351         /// <param name="disposing">true in order to free managed objects</param>
352         // Protected implementation of Dispose pattern.
353         [EditorBrowsable(EditorBrowsableState.Never)]
354         protected virtual void Dispose(bool disposing)
355         {
356             if (disposed)
357             {
358                 return;
359             }
360
361             if (disposing)
362             {
363                 // TODO: dispose managed state (managed objects).
364                 // Explicit call. user calls Dispose()
365
366                 //Throw exception if Dispose() is called in separate thread.
367                 if (!Window.IsInstalled())
368                 {
369                     using var process = global::System.Diagnostics.Process.GetCurrentProcess();
370                     var processId = process.Id;
371                     var thread = global::System.Threading.Thread.CurrentThread.ManagedThreadId;
372                     var me = this.GetType().FullName;
373
374                     DebugFileLogging.Instance.WriteLog("[NUI][BaseHandle] This API called from separate thread. This API must be called from MainThread. \n" +
375                         $" process:{processId} thread:{thread}, disposing:{disposing}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me}\n");
376
377                     Tizen.Log.Fatal("NUI", $"[NUI][BaseHandle] This API called from separate thread. This API must be called from MainThread. \n" +
378                         $" process:{processId} thread:{thread}, disposing:{disposing}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me}\n");
379
380                     //to fix ArtApp black screen issue. this will be enabled after talking with ArtApp team and fixing it.
381                     // throw new global::System.InvalidOperationException("[NUI][BaseHandle] This API called from separate thread. This API must be called from MainThread. \n" +
382                     //     $" process:{process} thread:{thread}, disposing:{disposing}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me}\n");
383                 }
384
385                 if (isDisposeQueued)
386                 {
387                     DebugFileLogging.Instance.WriteLog($"should not be here! (dead code) this will be removed!");
388
389                     Tizen.Log.Fatal("NUI", $"[NUI] should not be here! (dead code) this will be removed!");
390
391                     //to fix ArtApp black screen issue. this will be enabled after talking with ArtApp team and fixing it.
392                     // throw new global::System.Exception($"[NUI] should not be here! (dead code) this will be removed!");
393                     Dispose(DisposeTypes.Implicit);
394                 }
395                 else
396                 {
397                     Dispose(DisposeTypes.Explicit);
398                 }
399             }
400             else
401             {
402                 // Implicit call. user doesn't call Dispose(), so this object is added into DisposeQueue to be disposed automatically.
403                 if (!isDisposeQueued)
404                 {
405                     isDisposeQueued = true;
406                     DisposeQueue.Instance.Add(this);
407                 }
408             }
409
410             // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
411             // TODO: set large fields to null.
412         }
413
414
415         /// <summary>
416         /// Performs an action on this object with the given action name and attributes.
417         /// </summary>
418         /// <param name="actionName">The command for the action.</param>
419         /// <param name="attributes">The list of attributes for the action.</param>
420         /// <returns>The action is performed by the object or not.</returns>
421         /// <since_tizen> 3 </since_tizen>
422         public bool DoAction(string actionName, PropertyMap attributes)
423         {
424             bool ret = Interop.BaseHandle.DoAction(swigCPtr, actionName, PropertyMap.getCPtr(attributes));
425             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
426             return ret;
427         }
428
429         /// <summary>
430         /// Returns the type name for the Handle.<br />
431         /// Will return an empty string if the typename does not exist. This will happen for types that
432         /// have not registered with type-registry.
433         /// </summary>
434         /// <returns>The type name. Empty string if the typename does not exist.</returns>
435         /// <since_tizen> 3 </since_tizen>
436         public string GetTypeName()
437         {
438             string ret = Interop.BaseHandle.GetTypeName(swigCPtr);
439             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
440             return ret;
441         }
442
443         /// <summary>
444         /// Returns the type info for the Handle.<br />
445         /// </summary>
446         /// <param name="info">The type information.</param>
447         /// <returns>True If get the type info.</returns>
448         /// <since_tizen> 3 </since_tizen>
449         public bool GetTypeInfo(Tizen.NUI.TypeInfo info)
450         {
451             bool ret = Interop.BaseHandle.GetTypeInfo(swigCPtr, Tizen.NUI.TypeInfo.getCPtr(info));
452             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
453             return ret;
454         }
455
456         /// <summary>
457         /// Resets the handle.
458         /// </summary>
459         /// <since_tizen> 3 </since_tizen>
460         /// <remark>
461         /// This will be deprecated, please use Dispose() instead.
462         /// </remark>
463         public void Reset()
464         {
465             this.Dispose();
466             NUILog.Error("[ERROR] This(BaseHandle.Reset) will be deprecated, please use Dispose() instead!");
467         }
468
469         /// <summary>
470         /// To check the BaseHandle instance is equal or not.
471         /// </summary>
472         /// <param name="rhs">The baseHandle instance.</param>
473         /// <returns>True If equal.</returns>
474         /// <since_tizen> 3 </since_tizen>
475         public bool EqualTo(BaseHandle rhs)
476         {
477             bool ret = Interop.BaseHandle.EqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
478             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
479             return ret;
480         }
481
482         /// <summary>
483         /// To check the BaseHandle instance is equal or not.
484         /// </summary>
485         /// <param name="rhs">The baseHandle instance.</param>
486         /// <returns>True If not equal.</returns>
487         /// <since_tizen> 3 </since_tizen>
488         public bool NotEqualTo(BaseHandle rhs)
489         {
490             bool ret = Interop.BaseHandle.NotEqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
491             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
492             return ret;
493         }
494
495         /// <summary>
496         /// To check the BaseHandle instance has body or not.
497         /// </summary>
498         /// <returns>True If the baseHandle instance has body.</returns>
499         /// <since_tizen> 3 </since_tizen>
500         public bool HasBody()
501         {
502             if (swigCPtr.Handle == IntPtr.Zero)
503             {
504                 return false;
505             }
506
507             if (disposed == true)
508             {
509                 return false;
510             }
511             bool ret = Interop.BaseHandle.HasBody(swigCPtr);
512             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
513             return ret;
514         }
515
516         /// <summary>
517         /// To check the BaseHandle instance is equal or not.
518         /// </summary>
519         /// <param name="rhs">The baseHandle instance.</param>
520         /// <returns>True If equal.</returns>
521         /// <since_tizen> 3 </since_tizen>
522         public bool IsEqual(BaseHandle rhs)
523         {
524             if (disposed == true || rhs == null || !rhs.HasBody())
525             {
526                 return false;
527             }
528
529             bool ret = Interop.BaseHandle.IsEqual(swigCPtr, BaseHandle.getCPtr(rhs));
530             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
531             return ret;
532         }
533
534         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(BaseHandle obj)
535         {
536             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
537         }
538
539         internal void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
540         {
541             PropertySet?.Invoke(this, new PropertyChangedEventArgs(propertyName));
542         }
543
544         internal void UnregisterFromRegistry()
545         {
546             if (registerMe)
547             {
548                 Registry.Unregister(this);
549                 registerMe = false;
550             }
551         }
552
553         /// <summary>
554         /// Dispose.
555         /// </summary>
556         /// <since_tizen> 3 </since_tizen>
557         protected virtual void Dispose(DisposeTypes type)
558         {
559             if (disposed)
560             {
561                 return;
562             }
563
564             DebugFileLogging.Instance.WriteLog($"BaseHandle.Dispose({type}) START");
565
566             if (type == DisposeTypes.Explicit)
567             {
568                 //Called by User
569                 //Release your own managed resources here.
570                 //You should release all of your own disposable objects here.
571
572             }
573
574             //Release your own unmanaged resources here.
575             //You should not access any managed member here except static instance.
576             //because the execution order of Finalizes is non-deterministic.
577
578             //Unreference this instance from Registry.
579             UnregisterFromRegistry();
580
581             disposeDebuggingDispose(type);
582
583             if (SwigCPtr.Handle != IntPtr.Zero)
584             {
585                 var nativeSwigCPtr = swigCPtr.Handle;
586                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
587                 if (swigCMemOwn)
588                 {
589                     swigCMemOwn = false;
590                     ReleaseSwigCPtr(new global::System.Runtime.InteropServices.HandleRef(this, nativeSwigCPtr));
591                 }
592             }
593             else
594             {
595                 var me = this.GetType().FullName;
596                 DebugFileLogging.Instance.WriteLog($"[ERR] SwigCPtr is NULL, need to check! me:{me}");
597                 Log.Error("NUI", $"[ERR] SwigCPtr is NULL, need to check! me:{me}");
598             }
599
600             disposed = true;
601             DebugFileLogging.Instance.WriteLog($"BaseHandle.Dispose({type}) END");
602             DebugFileLogging.Instance.WriteLog($"=============================");
603             NUILog.Debug($"BaseHandle.Dispose({type}) END");
604             NUILog.Debug($"=============================");
605         }
606
607         /// <summary>
608         /// Release swigCPtr.
609         /// </summary>
610         /// <since_tizen> 6 </since_tizen>
611         /// This will not be public opened.
612         [EditorBrowsable(EditorBrowsableState.Never)]
613         protected virtual void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
614         {
615             Interop.BaseHandle.DeleteBaseHandle(swigCPtr.Handle);
616         }
617
618         /// <summary>
619         /// Contains event arguments for the FocusChangeRequested event.
620         /// </summary>
621         [Obsolete("Deprecated in API9; Will be removed in API11.")]
622         public class FocusRequestArgs : EventArgs
623         {
624
625             /// <summary>
626             /// Gets or sets a value that indicates the starting focus state of the element for which a focus change is requested.
627             /// </summary>
628             public bool Focus { get; set; }
629
630             /// <summary>
631             /// Gets or sets a value that indicates the ending focus state of the element for which a focus change is requested.
632             /// </summary>
633             public bool Result { get; set; }
634         }
635
636         internal global::System.Runtime.InteropServices.HandleRef SwigCPtr
637         {
638             get
639             {
640                 if (swigCPtr.Handle == IntPtr.Zero)
641                 {
642                     using var process = global::System.Diagnostics.Process.GetCurrentProcess();
643                     var processId = process.Id;
644                     var thread = global::System.Threading.Thread.CurrentThread.ManagedThreadId;
645                     var me = this.GetType().FullName;
646
647                     Tizen.Log.Fatal("NUI", $"SwigCPtr Error! NUI's native dali object is already disposed. " +
648                         $"OR the native dali object handle of NUI becomes null! \n" +
649                         $" process:{processId} thread:{thread}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me}\n");
650
651                     Tizen.Log.Fatal("NUI", $"[ERROR] back trace!");
652                     global::System.Diagnostics.StackTrace st = new global::System.Diagnostics.StackTrace(true);
653                     for (int i = 0; i < st.FrameCount; i++)
654                     {
655                         global::System.Diagnostics.StackFrame sf = st.GetFrame(i);
656                         Tizen.Log.Fatal("NUI", " Method " + sf.GetMethod() + ":" + sf.GetFileName() + ":" + sf.GetFileLineNumber());
657                     }
658                     Tizen.Log.Fatal("NUI", "Error! just return here with null swigCPtr! this can cause unknown error or crash in next step");
659
660                     //to fix ArtApp black screen issue. this will be enabled after talking with ArtApp team and fixing it.
661                     // throw new ObjectDisposedException(nameof(SwigCPtr), $"Error! NUI's native dali object is already disposed. " +
662                     //     $"OR the native dali object handle of NUI becomes null! \n" +
663                     //     $" process:{process} thread:{thread}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me}\n");
664                 }
665                 return swigCPtr;
666             }
667         }
668
669         internal bool IsNativeHandleInvalid()
670         {
671             return swigCPtr.Handle == IntPtr.Zero;
672         }
673
674         /// <summary>
675         /// swigCMemOwn
676         /// </summary>
677         [EditorBrowsable(EditorBrowsableState.Never)]
678         protected internal bool SwigCMemOwn => swigCMemOwn;
679
680         /// <summary>
681         /// The flag to check if it is already disposed of.
682         /// </summary>
683         [EditorBrowsable(EditorBrowsableState.Never)]
684         protected internal bool Disposed => disposed;
685
686         /// <summary>
687         /// The flag to check if it is disposed by DisposeQueue.
688         /// </summary>
689         [EditorBrowsable(EditorBrowsableState.Never)]
690         protected internal bool IsDisposeQueued => isDisposeQueued;
691
692         [Conditional("NUI_DISPOSE_DEBUG_ON")]
693         private void disposeDebuggingCtor()
694         {
695             DebugFileLogging.Instance.WriteLog($"type:{GetType()} copyNativeHandle:{swigCPtr.Handle.ToString("X8")}");
696             if (this is BaseComponents.View view)
697             {
698                 DebugFileLogging.Instance.WriteLog($"ID:{view.ID} Name:{view.Name}");
699                 //back trace
700                 global::System.Diagnostics.StackTrace st = new global::System.Diagnostics.StackTrace(true);
701                 for (int i = 0; i < st.FrameCount; i++)
702                 {
703                     global::System.Diagnostics.StackFrame sf = st.GetFrame(i);
704                     DebugFileLogging.Instance.WriteLog($"[{i}] {sf.GetMethod()}:{sf.GetFileName()}:{sf.GetFileLineNumber()}");
705                 }
706             }
707         }
708
709         [Conditional("NUI_DISPOSE_DEBUG_ON")]
710         private void disposeDebuggingDispose(DisposeTypes type)
711         {
712             DebugFileLogging.Instance.WriteLog($"swigCMemOwn:{swigCMemOwn} type:{GetType()} copyNativeHandle:{swigCPtr.Handle.ToString("X8")} HasBody:{HasBody()}");
713
714             if (HasBody())
715             {
716                 using var currentProcess = global::System.Diagnostics.Process.GetCurrentProcess();
717                 var process = currentProcess.Id;
718                 var thread = global::System.Threading.Thread.CurrentThread.ManagedThreadId;
719                 var me = this.GetType().FullName;
720                 var daliId = "unknown";
721                 var hash = this.GetType().GetHashCode();
722                 var name = "unknown";
723
724                 if (this is BaseComponents.View)
725                 {
726                     daliId = Interop.Actor.GetId(swigCPtr).ToString();
727                     name = Interop.Actor.GetName(swigCPtr);
728                     BaseObject tmp = new BaseObject(Interop.BaseHandle.GetBaseObject(swigCPtr), false);
729                     var refCnt = tmp.ReferenceCount();
730                     tmp.Dispose();
731                     if (refCnt > 2)
732                     {
733                         DebugFileLogging.Instance.WriteLog($"[ERR] reference count is over than 2. Could be a memory leak. Need to check! \n" +
734                             $" process:{process} thread:{thread}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me} \n" +
735                             $" disposeType:{type}, name:{name}, daliID:{daliId}, hash:{hash}, refCnt:{refCnt}");
736
737                         Log.Error("NUI", $"[ERR] reference count is over than 2. Could be a memory leak. Need to check! \n" +
738                             $" process:{process} thread:{thread}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me} \n" +
739                             $" disposeType:{type}, name:{name}, daliID:{daliId}, hash:{hash}, refCnt:{refCnt}");
740                     }
741                 }
742             }
743         }
744
745     }
746 }