[NUI] Fix some SVACE issues.
authorzhouhao02 <haozhou.zhou@samsung.com>
Fri, 1 Dec 2023 06:07:21 +0000 (14:07 +0800)
committerBowon Ryu <wonrst22@naver.com>
Tue, 5 Dec 2023 07:45:45 +0000 (16:45 +0900)
src/Tizen.NUI.Physics2D/src/internal/chipmunk/NativeInterop.cs
src/Tizen.NUI.Physics2D/src/internal/chipmunk/cpSpaceDebugDrawOptions.cs
src/Tizen.NUI/src/public/BaseComponents/DirectRenderingGLView.cs

index a86f6bf4ce6d2159569427c59d2d4a735abc376a..063968c4f69dc16a7d5da9d203a8234fafe7fbca 100644 (file)
@@ -81,6 +81,9 @@ namespace Tizen.NUI.Physics2D.Chipmunk
         public static IntPtr AllocStructure<T>()
         {
             int size = SizeOf<T>();
+
+            Debug.Assert(size>0, "The memory size to be allocated should be greater than 0");
+
             return Marshal.AllocHGlobal(size);
         }
 
index 7b9afef9716e2658d8c807eccfe7c9a8fd913835..6e3366fb13769ff48134f2ecaa53064500a7b893 100644 (file)
@@ -104,10 +104,6 @@ namespace Tizen.NUI.Physics2D.Chipmunk
         private IntPtr ToPointer()
         {
             IntPtr drawOptionsPtr = NativeInterop.AllocStructure<cpSpaceDebugDrawOptions>();
-            if (Marshal.SizeOf(typeof(cpSpaceDebugDrawOptions)) == 0)
-            {
-                throw new ArgumentNullException("The size of type cpSpaceDebugDrawOptions should not be 0.");
-            }
 
             Marshal.StructureToPtr<cpSpaceDebugDrawOptions>(this, drawOptionsPtr, false);
 
index 2946cb4ebbafeb24a3d4d0b6dfb65deef5ede6b7..63dbda6c8c8b9879f31e597c0d0952d066215afd 100644 (file)
@@ -186,18 +186,19 @@ namespace Tizen.NUI.BaseComponents
                 
                 if (textures != null)
                 {
-                    int intptrBytes = checked(sizeof(IntPtr) * textures.Count);
+                    int count = textures.Count;
+                    int intptrBytes = checked(sizeof(IntPtr) * count);
                     if (intptrBytes>0)
                     {
                         IntPtr unmanagedPointer = Marshal.AllocHGlobal(intptrBytes);
-                        IntPtr[] texturesArray = new IntPtr[textures.Count];
-                        for (int i = 0; i < textures.Count; i++)
+                        IntPtr[] texturesArray = new IntPtr[count];
+                        for (int i = 0; i < count; i++)
                         {
                             texturesArray[i] = HandleRef.ToIntPtr(Texture.getCPtr(textures[i]));
                         }
-                        System.Runtime.InteropServices.Marshal.Copy(texturesArray, 0, unmanagedPointer, textures.Count);
+                        Marshal.Copy(texturesArray, 0, unmanagedPointer, count);
 
-                        Interop.GLView.GlViewBindTextureResources(SwigCPtr, unmanagedPointer, textures.Count);
+                        Interop.GLView.GlViewBindTextureResources(SwigCPtr, unmanagedPointer, count);
                         Marshal.FreeHGlobal(unmanagedPointer);
                     }
                 }