From 88f8490be544cd14b8f27e711a70687a283bd50e Mon Sep 17 00:00:00 2001 From: "huayong.xu" Date: Mon, 28 Apr 2025 16:12:01 +0800 Subject: [PATCH] [NUI] Fix some CA2000 warnings in NUI. Meanwhile some memory leaks are fixed. For example, Vector2.Dispose is not called in Wheel constructor. --- src/Tizen.NUI/src/internal/Animation/Constraint.cs | 5 +++-- src/Tizen.NUI/src/public/Common/PropertyArray.cs | 1 - src/Tizen.NUI/src/public/Events/Wheel.cs | 3 +-- src/Tizen.NUI/src/public/Utility/Capture.cs | 9 ++++++--- src/Tizen.NUI/src/public/Visuals/AnimatedImageVisual.cs | 6 ++++-- .../public/Visuals/VisualObject/AnimatedImageVisual.cs | 6 ++++-- src/Tizen.NUI/src/public/Window/MouseInOut.cs | 3 +-- src/Tizen.NUI/src/public/Window/MouseRelative.cs | 3 +-- 8 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/Tizen.NUI/src/internal/Animation/Constraint.cs b/src/Tizen.NUI/src/internal/Animation/Constraint.cs index 4ffd6b65d..69796ced3 100755 --- a/src/Tizen.NUI/src/internal/Animation/Constraint.cs +++ b/src/Tizen.NUI/src/internal/Animation/Constraint.cs @@ -467,13 +467,14 @@ namespace Tizen.NUI if (ret != null) { Interop.BaseHandle.DeleteBaseHandle(new global::System.Runtime.InteropServices.HandleRef(this, cPtr)); + NDalicPINVOKE.ThrowExceptionIfExists(); + return ret; } else { ret = new Animatable(cPtr, true); + return ret; } - NDalicPINVOKE.ThrowExceptionIfExists(); - return ret; } /// diff --git a/src/Tizen.NUI/src/public/Common/PropertyArray.cs b/src/Tizen.NUI/src/public/Common/PropertyArray.cs index b499d38e9..a2af5447a 100755 --- a/src/Tizen.NUI/src/public/Common/PropertyArray.cs +++ b/src/Tizen.NUI/src/public/Common/PropertyArray.cs @@ -173,7 +173,6 @@ namespace Tizen.NUI public PropertyArray Add(PropertyValue value) { PropertyArray ret = new PropertyArray(Interop.Property.ArrayAdd(SwigCPtr, PropertyValue.getCPtr(value)), false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } diff --git a/src/Tizen.NUI/src/public/Events/Wheel.cs b/src/Tizen.NUI/src/public/Events/Wheel.cs index a07b7b672..141528daf 100755 --- a/src/Tizen.NUI/src/public/Events/Wheel.cs +++ b/src/Tizen.NUI/src/public/Events/Wheel.cs @@ -28,12 +28,11 @@ namespace Tizen.NUI /// 3 public class Wheel : BaseHandle { - /// /// The default constructor of Wheel class. /// /// 3 - public Wheel() : this(Interop.Wheel.New(0, 0, 0u, Vector2.getCPtr(new Vector2(0.0f, 0.0f)), 0, 0u), true) + public Wheel() : this(Interop.Wheel.New(0, 0, 0u, Vector2.getCPtr(Vector2.Zero), 0, 0u), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } diff --git a/src/Tizen.NUI/src/public/Utility/Capture.cs b/src/Tizen.NUI/src/public/Utility/Capture.cs index e618ac649..0b9d2275b 100755 --- a/src/Tizen.NUI/src/public/Utility/Capture.cs +++ b/src/Tizen.NUI/src/public/Utility/Capture.cs @@ -154,7 +154,8 @@ namespace Tizen.NUI { using var posVector2 = new Vector2(position.X, position.Y); using var sizeVector2 = new Vector2(size.Width, size.Height); - Interop.Capture.Start4(SwigCPtr, source.SwigCPtr, posVector2.SwigCPtr, sizeVector2.SwigCPtr, path, new Vector4(color.R, color.G, color.B, color.A).SwigCPtr); + using var colorVector4 = new Vector4(color.R, color.G, color.B, color.A); + Interop.Capture.Start4(SwigCPtr, source.SwigCPtr, posVector2.SwigCPtr, sizeVector2.SwigCPtr, path, colorVector4.SwigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } @@ -199,7 +200,8 @@ namespace Tizen.NUI if (source is View || source is Layer) { using var sizeVector2 = new Vector2(size.Width, size.Height); - Interop.Capture.Start3(SwigCPtr, source.SwigCPtr, sizeVector2.SwigCPtr, path, new Vector4(color.R, color.G, color.B, color.A).SwigCPtr, quality); + using var colorVector4 = new Vector4(color.R, color.G, color.B, color.A); + Interop.Capture.Start3(SwigCPtr, source.SwigCPtr, sizeVector2.SwigCPtr, path, colorVector4.SwigCPtr, quality); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } @@ -239,7 +241,8 @@ namespace Tizen.NUI if (source is View || source is Layer) { using var sizeVector2 = new Vector2(size.Width, size.Height); - Interop.Capture.Start1(SwigCPtr, source.SwigCPtr, sizeVector2.SwigCPtr, path, new Vector4(color.R, color.G, color.B, color.A).SwigCPtr); + using var colorVector4 = new Vector4(color.R, color.G, color.B, color.A); + Interop.Capture.Start1(SwigCPtr, source.SwigCPtr, sizeVector2.SwigCPtr, path, colorVector4.SwigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } diff --git a/src/Tizen.NUI/src/public/Visuals/AnimatedImageVisual.cs b/src/Tizen.NUI/src/public/Visuals/AnimatedImageVisual.cs index 8182f6194..39bc1b27f 100755 --- a/src/Tizen.NUI/src/public/Visuals/AnimatedImageVisual.cs +++ b/src/Tizen.NUI/src/public/Visuals/AnimatedImageVisual.cs @@ -176,8 +176,10 @@ namespace Tizen.NUI using var urlArray = new PropertyArray(); foreach (var url in urls) { - var pv = new PropertyValue(url); - using var _ = urlArray.Add(pv); + using (var pv = new PropertyValue(url)) + { + using var _ = urlArray.Add(pv); + } } using (var temp = new PropertyValue(urlArray)) { diff --git a/src/Tizen.NUI/src/public/Visuals/VisualObject/AnimatedImageVisual.cs b/src/Tizen.NUI/src/public/Visuals/VisualObject/AnimatedImageVisual.cs index fd1ceb089..5caa04b27 100644 --- a/src/Tizen.NUI/src/public/Visuals/VisualObject/AnimatedImageVisual.cs +++ b/src/Tizen.NUI/src/public/Visuals/VisualObject/AnimatedImageVisual.cs @@ -296,8 +296,10 @@ namespace Tizen.NUI.Visuals using var urlArray = new PropertyArray(); foreach (var url in resourceUrls) { - var urlValue = new PropertyValue(url); - using var _ = urlArray.Add(urlValue); + using (var urlValue = new PropertyValue(url)) + { + using var _ = urlArray.Add(urlValue); + } } if (cachedVisualPropertyMap != null) diff --git a/src/Tizen.NUI/src/public/Window/MouseInOut.cs b/src/Tizen.NUI/src/public/Window/MouseInOut.cs index 31e5dfe4f..053d75346 100755 --- a/src/Tizen.NUI/src/public/Window/MouseInOut.cs +++ b/src/Tizen.NUI/src/public/Window/MouseInOut.cs @@ -25,12 +25,11 @@ namespace Tizen.NUI [EditorBrowsable(EditorBrowsableState.Never)] public class MouseInOut : Disposable { - /// /// The default constructor. /// [EditorBrowsable(EditorBrowsableState.Never)] - public MouseInOut() : this(Interop.MouseInOut.NewMouseInOut((int)MouseInOut.StateType.None, 0, Vector2.getCPtr(new Vector2(0, 0)), 0), true) + public MouseInOut() : this(Interop.MouseInOut.NewMouseInOut((int)MouseInOut.StateType.None, 0, Vector2.getCPtr(Vector2.Zero), 0), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } diff --git a/src/Tizen.NUI/src/public/Window/MouseRelative.cs b/src/Tizen.NUI/src/public/Window/MouseRelative.cs index 8ec7a992d..258603f2f 100755 --- a/src/Tizen.NUI/src/public/Window/MouseRelative.cs +++ b/src/Tizen.NUI/src/public/Window/MouseRelative.cs @@ -25,12 +25,11 @@ namespace Tizen.NUI [EditorBrowsable(EditorBrowsableState.Never)] public class MouseRelative : Disposable { - /// /// The default constructor. /// [EditorBrowsable(EditorBrowsableState.Never)] - public MouseRelative() : this(Interop.MouseRelative.NewMouseRelative((int)MouseRelative.StateType.None, 0, 0, Vector2.getCPtr(new Vector2(0, 0)), Vector2.getCPtr(new Vector2(0, 0))), true) + public MouseRelative() : this(Interop.MouseRelative.NewMouseRelative((int)MouseRelative.StateType.None, 0, 0, Vector2.getCPtr(Vector2.Zero), Vector2.getCPtr(Vector2.Zero)), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } -- 2.34.1