internal static IntPtr StructureArrayToPtr<T>(IReadOnlyList<T> items)
{
var size = SizeOf<T>();
- var memory = Marshal.AllocHGlobal(size * items.Count);
+ int allocBytes = checked(size * items.Count);
+ Debug.Assert(allocBytes > 0, "The memory to be allocated should be greater than 0");
+
+ var memory = Marshal.AllocHGlobal(allocBytes);
for (var i = 0; i < items.Count; i++)
{
private IntPtr ToPointer()
{
IntPtr drawOptionsPtr = NativeInterop.AllocStructure<cpSpaceDebugDrawOptions>();
-
- Marshal.StructureToPtr<cpSpaceDebugDrawOptions>(this, drawOptionsPtr, false);
+ try
+ {
+ Marshal.StructureToPtr<cpSpaceDebugDrawOptions>(this, drawOptionsPtr, false);
+ }
+ catch (Exception exception)
+ {
+ Tizen.Log.Fatal("NUI", "[Error] got exception during Marshal.StructureToPtr, this should not occur, message : " + exception.Message);
+ }
+
return drawOptionsPtr;
}
get
{
int count = NativeMethods.cpBodyGetContactedBodiesCount(body);
+ int intptrBytes = checked(IntPtr.Size * count);
- if (count == 0)
+ if (intptrBytes == 0)
return Array.Empty<Body>();
- IntPtr ptrBodies = Marshal.AllocHGlobal(IntPtr.Size * count);
+ IntPtr ptrBodies = Marshal.AllocHGlobal(intptrBytes);
NativeMethods.cpBodyGetUserDataContactedBodies(body, ptrBodies);
IntPtr[] userDataArray = new IntPtr[count];
get
{
int count = NativeMethods.cpSpaceGetBodyCount(space);
+ int intptrBytes = checked(IntPtr.Size * count);
- if (count == 0)
+ if (intptrBytes == 0)
return Array.Empty<Body>();
- IntPtr ptrBodies = Marshal.AllocHGlobal(IntPtr.Size * count);
+ IntPtr ptrBodies = Marshal.AllocHGlobal(intptrBytes);
NativeMethods.cpSpaceGetBodiesUserDataArray(space, ptrBodies);
IntPtr[] userDataArray = new IntPtr[count];
get
{
int count = NativeMethods.cpSpaceGetDynamicBodyCount(space);
+ int intptrBytes = checked(IntPtr.Size * count);
- if (count == 0)
+ if (intptrBytes == 0)
return Array.Empty<Body>();
- IntPtr ptrBodies = Marshal.AllocHGlobal(IntPtr.Size * count);
+ IntPtr ptrBodies = Marshal.AllocHGlobal(intptrBytes);
NativeMethods.cpSpaceGetDynamicBodiesUserDataArray(space, ptrBodies);
IntPtr[] userDataArray = new IntPtr[count];
get
{
int count = NativeMethods.cpSpaceGetBodyCount(space);
+ int intptrBytes = checked(IntPtr.Size * count);
- if (count == 0)
+ if (intptrBytes == 0)
return Array.Empty<Body>();
- IntPtr ptrBodies = Marshal.AllocHGlobal(IntPtr.Size * count);
+ IntPtr ptrBodies = Marshal.AllocHGlobal(intptrBytes);
NativeMethods.cpSpaceGetBodiesUserDataArray(space, ptrBodies);
IntPtr[] userDataArray = new IntPtr[count];
get
{
int count = NativeMethods.cpSpaceGetDynamicBodyCount(space);
+ int intptrBytes = checked(IntPtr.Size * count);
- if (count == 0)
+ if (intptrBytes == 0)
return Array.Empty<Body>();
- IntPtr ptrBodies = Marshal.AllocHGlobal(IntPtr.Size * count);
+ IntPtr ptrBodies = Marshal.AllocHGlobal(intptrBytes);
NativeMethods.cpSpaceGetDynamicBodiesUserDataArray(space, ptrBodies);
IntPtr[] userDataArray = new IntPtr[count];