From: Eunki Hong Date: Fri, 19 Jan 2024 01:28:11 +0000 (+0900) Subject: [NUI] Fix some incorrect implements when we get Texture relative items X-Git-Tag: submit/tizen/20240124.080400~1^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=26e6342b15b398ea35bae71d4da4431758860508;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] Fix some incorrect implements when we get Texture relative items Since now we have a unified pattern to avoid memory leak problem between NUI and Native side handle count problem, Let we change some mis-implementated codes relative with Texture. Signed-off-by: Eunki Hong --- diff --git a/src/Tizen.NUI/src/internal/Common/FrameBuffer.cs b/src/Tizen.NUI/src/internal/Common/FrameBuffer.cs index dc8ee2255..d0efc5178 100755 --- a/src/Tizen.NUI/src/internal/Common/FrameBuffer.cs +++ b/src/Tizen.NUI/src/internal/Common/FrameBuffer.cs @@ -66,10 +66,17 @@ namespace Tizen.NUI public Texture GetColorTexture() { - //to fix memory leak issue, match the handle count with native side. global::System.IntPtr cPtr = Interop.FrameBuffer.GetColorTexture(SwigCPtr); - Texture ret = this.GetInstanceSafely(cPtr); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + Texture ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Texture; + if (ret != null) + { + Interop.BaseHandle.DeleteBaseHandle(new global::System.Runtime.InteropServices.HandleRef(this, cPtr)); + } + else + { + ret = new Texture(cPtr, true); + } + NDalicPINVOKE.ThrowExceptionIfExists(); return ret; } diff --git a/src/Tizen.NUI/src/internal/Transition/TransitionSet.cs b/src/Tizen.NUI/src/internal/Transition/TransitionSet.cs index 0750567c3..aec4a564c 100755 --- a/src/Tizen.NUI/src/internal/Transition/TransitionSet.cs +++ b/src/Tizen.NUI/src/internal/Transition/TransitionSet.cs @@ -118,22 +118,17 @@ namespace Tizen.NUI public TransitionItemBase GetTransitionAt(uint index) { - //to fix memory leak issue, match the handle count with native side. IntPtr cPtr = Interop.TransitionSet.GetTransitionAt(SwigCPtr, index); - HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); - TransitionItemBase ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as TransitionItemBase; - if (cPtr != IntPtr.Zero && ret == null) + TransitionItemBase ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as TransitionItemBase; + if (ret != null) { - ret = new TransitionItemBase(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; + Interop.BaseHandle.DeleteBaseHandle(new HandleRef(this, cPtr)); } - Interop.BaseHandle.DeleteBaseHandle(CPtr); - CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); - - if (NDalicPINVOKE.SWIGPendingException.Pending) - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + else + { + ret = new TransitionItemBase(cPtr, true); + } + NDalicPINVOKE.ThrowExceptionIfExists(); return ret; } diff --git a/src/Tizen.NUI/src/public/BaseComponents/ViewPublicMethods.cs b/src/Tizen.NUI/src/public/BaseComponents/ViewPublicMethods.cs index ce45a7c2a..5da4b3bb9 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewPublicMethods.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewPublicMethods.cs @@ -613,22 +613,17 @@ namespace Tizen.NUI.BaseComponents /// 3 public Renderer GetRendererAt(uint index) { - //to fix memory leak issue, match the handle count with native side. IntPtr cPtr = Interop.Actor.GetRendererAt(SwigCPtr, index); - HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); - Renderer ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as Renderer; - if (cPtr != IntPtr.Zero && ret == null) + Renderer ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Renderer; + if (ret != null) { - ret = new Renderer(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; + Interop.BaseHandle.DeleteBaseHandle(new HandleRef(this, cPtr)); } - Interop.BaseHandle.DeleteBaseHandle(CPtr); - CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); - - if (NDalicPINVOKE.SWIGPendingException.Pending) - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + else + { + ret = new Renderer(cPtr, true); + } + NDalicPINVOKE.ThrowExceptionIfExists(); return ret; } diff --git a/src/Tizen.NUI/src/public/Rendering/Renderer.cs b/src/Tizen.NUI/src/public/Rendering/Renderer.cs index 77d521386..fbc4b3f26 100755 --- a/src/Tizen.NUI/src/public/Rendering/Renderer.cs +++ b/src/Tizen.NUI/src/public/Rendering/Renderer.cs @@ -766,20 +766,17 @@ namespace Tizen.NUI /// 3 public TextureSet GetTextures() { - //to fix memory leak issue, match the handle count with native side. - System.IntPtr cPtr = Interop.Renderer.GetTextures(SwigCPtr); - HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); - TextureSet ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as TextureSet; - if (cPtr != IntPtr.Zero && ret == null) + global::System.IntPtr cPtr = Interop.Renderer.GetTextures(SwigCPtr); + TextureSet ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as TextureSet; + if (ret != null) { - ret = new TextureSet(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; + Interop.BaseHandle.DeleteBaseHandle(new global::System.Runtime.InteropServices.HandleRef(this, cPtr)); } - Interop.BaseHandle.DeleteBaseHandle(CPtr); - CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); - - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + else + { + ret = new TextureSet(cPtr, true); + } + NDalicPINVOKE.ThrowExceptionIfExists(); return ret; } diff --git a/src/Tizen.NUI/src/public/Rendering/TextureSet.cs b/src/Tizen.NUI/src/public/Rendering/TextureSet.cs index 3ad33027f..664aa3af5 100755 --- a/src/Tizen.NUI/src/public/Rendering/TextureSet.cs +++ b/src/Tizen.NUI/src/public/Rendering/TextureSet.cs @@ -60,20 +60,17 @@ namespace Tizen.NUI /// 3 public Texture GetTexture(uint index) { - //to fix memory leak issue, match the handle count with native side. - System.IntPtr cPtr = Interop.TextureSet.GetTexture(SwigCPtr, index); - HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); - Texture ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as Texture; - if (cPtr != System.IntPtr.Zero && ret == null) + global::System.IntPtr cPtr = Interop.TextureSet.GetTexture(SwigCPtr, index); + Texture ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Texture; + if (ret != null) { - ret = new Texture(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; + Interop.BaseHandle.DeleteBaseHandle(new global::System.Runtime.InteropServices.HandleRef(this, cPtr)); } - Interop.BaseHandle.DeleteBaseHandle(CPtr); - CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); - - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + else + { + ret = new Texture(cPtr, true); + } + NDalicPINVOKE.ThrowExceptionIfExists(); return ret; } @@ -97,10 +94,17 @@ namespace Tizen.NUI /// 3 public Sampler GetSampler(uint index) { - //to fix memory leak issue, match the handle count with native side. - System.IntPtr cPtr = Interop.TextureSet.GetSampler(SwigCPtr, index); - Sampler ret = this.GetInstanceSafely(cPtr); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + global::System.IntPtr cPtr = Interop.TextureSet.GetSampler(SwigCPtr, index); + Sampler ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Sampler; + if (ret != null) + { + Interop.BaseHandle.DeleteBaseHandle(new global::System.Runtime.InteropServices.HandleRef(this, cPtr)); + } + else + { + ret = new Sampler(cPtr, true); + } + NDalicPINVOKE.ThrowExceptionIfExists(); return ret; }