From: Eunki Hong Date: Thu, 12 Oct 2023 14:24:45 +0000 (+0900) Subject: [NUI] Fix Registry exception for custom view wrapper X-Git-Tag: submit/tizen/20231025.151412~1^2~17 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=49f5d2035ca9d1f20083e3c0ee1192e15af3e02f;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] Fix Registry exception for custom view wrapper 1. PanGesture from Accessibility create new handle in dali csharp side. We need to have memory ownership, but don't need to register it on NUI side. We can ignore it. 2. For Animation and StyleManager, it is possible to use that 'already registered' BaseHandle. But in this case, we should not dispose it by our self. Signed-off-by: Eunki Hong --- diff --git a/src/Tizen.NUI/src/internal/Common/ViewWrapperImpl.cs b/src/Tizen.NUI/src/internal/Common/ViewWrapperImpl.cs index 63314650c..fcb85a1d7 100755 --- a/src/Tizen.NUI/src/internal/Common/ViewWrapperImpl.cs +++ b/src/Tizen.NUI/src/internal/Common/ViewWrapperImpl.cs @@ -389,11 +389,30 @@ namespace Tizen.NUI private void DirectorOnSizeAnimation(global::System.IntPtr animation, global::System.IntPtr targetSize) { - var ani = new Animation(animation, true); + bool useRegisterAnimation = false; + + var ani = Registry.GetManagedBaseHandleFromNativePtr(animation) as Animation; + if (ani != null) + { + HandleRef CPtr = new HandleRef(this, animation); + Interop.BaseHandle.DeleteBaseHandle(CPtr); + CPtr = new HandleRef(null, global::System.IntPtr.Zero); + + useRegisterAnimation = true; + } + else + { + ani = new Animation(animation, true); + } var vector3 = new Vector3(targetSize, false); OnSizeAnimation?.Invoke(ani, vector3); - ani.Dispose(); vector3.Dispose(); + + // Dispose only if we create new Animation here. + if (!useRegisterAnimation) + { + ani.Dispose(); + } } private bool DirectorOnKey(global::System.IntPtr arg0) @@ -469,9 +488,28 @@ namespace Tizen.NUI private void DirectorOnStyleChange(global::System.IntPtr styleManager, int change) { - var styleManger = new StyleManager(styleManager, true); - OnStyleChange?.Invoke(styleManger, (StyleChangeType)change); - styleManger.Dispose(); + bool useRegisterStyleManager = false; + + var nuiStyleManger = Registry.GetManagedBaseHandleFromNativePtr(styleManager) as StyleManager; + if (nuiStyleManger != null) + { + HandleRef CPtr = new HandleRef(this, styleManager); + Interop.BaseHandle.DeleteBaseHandle(CPtr); + CPtr = new HandleRef(null, global::System.IntPtr.Zero); + + useRegisterStyleManager = true; + } + else + { + nuiStyleManger = new StyleManager(styleManager, true); + } + OnStyleChange?.Invoke(nuiStyleManger, (StyleChangeType)change); + + // Dispose only if we create new StyleManager here. + if (!useRegisterStyleManager) + { + nuiStyleManger.Dispose(); + } } private bool DirectorOnAccessibilityActivated() @@ -481,7 +519,8 @@ namespace Tizen.NUI private bool DirectorOnAccessibilityPan(global::System.IntPtr gesture) { - var panGesture = new PanGesture(gesture, true); + // Take memory ownership, but do not register into Registry. + var panGesture = new PanGesture(gesture, true, false); var ret = OnAccessibilityPan?.Invoke(panGesture) ?? false; panGesture.Dispose(); return ret; diff --git a/src/Tizen.NUI/src/public/Events/Gesture.cs b/src/Tizen.NUI/src/public/Events/Gesture.cs index 9eb8b6fc6..87f015e86 100755 --- a/src/Tizen.NUI/src/public/Events/Gesture.cs +++ b/src/Tizen.NUI/src/public/Events/Gesture.cs @@ -37,7 +37,11 @@ namespace Tizen.NUI if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } - internal Gesture(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) + internal Gesture(global::System.IntPtr cPtr, bool cMemoryOwn) : this(cPtr, cMemoryOwn, cMemoryOwn) + { + } + + internal Gesture(global::System.IntPtr cPtr, bool cMemoryOwn, bool cRegister) : base(cPtr, cMemoryOwn, cRegister) { } diff --git a/src/Tizen.NUI/src/public/Events/LongPressGesture.cs b/src/Tizen.NUI/src/public/Events/LongPressGesture.cs index ff21038d6..14e63ff06 100755 --- a/src/Tizen.NUI/src/public/Events/LongPressGesture.cs +++ b/src/Tizen.NUI/src/public/Events/LongPressGesture.cs @@ -35,7 +35,11 @@ namespace Tizen.NUI if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } - internal LongPressGesture(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) + internal LongPressGesture(global::System.IntPtr cPtr, bool cMemoryOwn) : this(cPtr, cMemoryOwn, cMemoryOwn) + { + } + + internal LongPressGesture(global::System.IntPtr cPtr, bool cMemoryOwn, bool cRegister) : base(cPtr, cMemoryOwn, cRegister) { } diff --git a/src/Tizen.NUI/src/public/Events/PanGesture.cs b/src/Tizen.NUI/src/public/Events/PanGesture.cs index 7e4fadf66..8587a69af 100755 --- a/src/Tizen.NUI/src/public/Events/PanGesture.cs +++ b/src/Tizen.NUI/src/public/Events/PanGesture.cs @@ -49,7 +49,11 @@ namespace Tizen.NUI if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } - internal PanGesture(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.PanGestureDetector.PanGestureUpcast(cPtr), cMemoryOwn) + internal PanGesture(global::System.IntPtr cPtr, bool cMemoryOwn) : this(Interop.PanGestureDetector.PanGestureUpcast(cPtr), cMemoryOwn, cMemoryOwn) + { + } + + internal PanGesture(global::System.IntPtr cPtr, bool cMemoryOwn, bool cRegister) : base(Interop.PanGestureDetector.PanGestureUpcast(cPtr), cMemoryOwn, cRegister) { } diff --git a/src/Tizen.NUI/src/public/Events/PinchGesture.cs b/src/Tizen.NUI/src/public/Events/PinchGesture.cs index 10394b252..25be2635b 100755 --- a/src/Tizen.NUI/src/public/Events/PinchGesture.cs +++ b/src/Tizen.NUI/src/public/Events/PinchGesture.cs @@ -25,7 +25,11 @@ namespace Tizen.NUI /// 3 public class PinchGesture : Gesture { - internal PinchGesture(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) + internal PinchGesture(global::System.IntPtr cPtr, bool cMemoryOwn) : this(cPtr, cMemoryOwn, cMemoryOwn) + { + } + + internal PinchGesture(global::System.IntPtr cPtr, bool cMemoryOwn, bool cRegister) : base(cPtr, cMemoryOwn, cRegister) { } diff --git a/src/Tizen.NUI/src/public/Events/RotationGesture.cs b/src/Tizen.NUI/src/public/Events/RotationGesture.cs index 7057c713c..a56583289 100755 --- a/src/Tizen.NUI/src/public/Events/RotationGesture.cs +++ b/src/Tizen.NUI/src/public/Events/RotationGesture.cs @@ -26,8 +26,11 @@ namespace Tizen.NUI [EditorBrowsable(EditorBrowsableState.Never)] public class RotationGesture : Gesture { + internal RotationGesture(global::System.IntPtr cPtr, bool cMemoryOwn) : this(cPtr, cMemoryOwn, cMemoryOwn) + { + } - internal RotationGesture(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) + internal RotationGesture(global::System.IntPtr cPtr, bool cMemoryOwn, bool cRegister) : base(cPtr, cMemoryOwn, cRegister) { } diff --git a/src/Tizen.NUI/src/public/Events/TapGesture.cs b/src/Tizen.NUI/src/public/Events/TapGesture.cs index 71045114d..f9fe98181 100755 --- a/src/Tizen.NUI/src/public/Events/TapGesture.cs +++ b/src/Tizen.NUI/src/public/Events/TapGesture.cs @@ -36,7 +36,11 @@ namespace Tizen.NUI if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } - internal TapGesture(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) + internal TapGesture(global::System.IntPtr cPtr, bool cMemoryOwn) : this(cPtr, cMemoryOwn, cMemoryOwn) + { + } + + internal TapGesture(global::System.IntPtr cPtr, bool cMemoryOwn, bool cRegister) : base(cPtr, cMemoryOwn, cRegister) { }