Skip to content

2-dimensional arrays inside structs not generated properly #1238

Open
@zghonda

Description

@zghonda
Brief Description

Hello,

I noticed that the binding code for my 2-dimensional array used to represent a matrix is not correctly generated.

So my question is : Do you support multidimensional arrays ?

Here's a small code to illustrate the problem

Thank you in advance

OS: Windows, binaries compiled for amd64

Used headers
__declspec(dllexport) struct matrix3x3{
    float matrix[3][3];
};

Used settings

Exactly the same as the official tutorial

Target: MSVC

Generated code

(No accessors for my matrix)

namespace MatrixIssue
{
    public unsafe partial class Matrix3x3 : IDisposable
    {
        [StructLayout(LayoutKind.Explicit, Size = 36)]
        public partial struct __Internal
        {
            [FieldOffset(0)]
            internal fixed float matrix[9];

            [SuppressUnmanagedCodeSecurity]
            [DllImport("MatrixIssue", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
                EntryPoint="??0matrix3x3@@QEAA@AEBU0@@Z")]
            internal static extern global::System.IntPtr cctor(global::System.IntPtr __instance, global::System.IntPtr _0);
        }

        public global::System.IntPtr __Instance { get; protected set; }

        protected int __PointerAdjustment;
        internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::MatrixIssue.Matrix3x3> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::MatrixIssue.Matrix3x3>();
        protected internal void*[] __OriginalVTables;

        protected bool __ownsNativeInstance;

        internal static global::MatrixIssue.Matrix3x3 __CreateInstance(global::System.IntPtr native, bool skipVTables = false)
        {
            return new global::MatrixIssue.Matrix3x3(native.ToPointer(), skipVTables);
        }

        internal static global::MatrixIssue.Matrix3x3 __CreateInstance(global::MatrixIssue.Matrix3x3.__Internal native, bool skipVTables = false)
        {
            return new global::MatrixIssue.Matrix3x3(native, skipVTables);
        }

        private static void* __CopyValue(global::MatrixIssue.Matrix3x3.__Internal native)
        {
            var ret = Marshal.AllocHGlobal(sizeof(global::MatrixIssue.Matrix3x3.__Internal));
            *(global::MatrixIssue.Matrix3x3.__Internal*) ret = native;
            return ret.ToPointer();
        }

        private Matrix3x3(global::MatrixIssue.Matrix3x3.__Internal native, bool skipVTables = false)
            : this(__CopyValue(native), skipVTables)
        {
            __ownsNativeInstance = true;
            NativeToManagedMap[__Instance] = this;
        }

        protected Matrix3x3(void* native, bool skipVTables = false)
        {
            if (native == null)
                return;
            __Instance = new global::System.IntPtr(native);
        }

        public Matrix3x3()
        {
            __Instance = Marshal.AllocHGlobal(sizeof(global::MatrixIssue.Matrix3x3.__Internal));
            __ownsNativeInstance = true;
            NativeToManagedMap[__Instance] = this;
        }

        public Matrix3x3(global::MatrixIssue.Matrix3x3 _0)
        {
            __Instance = Marshal.AllocHGlobal(sizeof(global::MatrixIssue.Matrix3x3.__Internal));
            __ownsNativeInstance = true;
            NativeToManagedMap[__Instance] = this;
            *((global::MatrixIssue.Matrix3x3.__Internal*) __Instance) = *((global::MatrixIssue.Matrix3x3.__Internal*) _0.__Instance);
        }

        public void Dispose()
        {
            Dispose(disposing: true);
        }

        public virtual void Dispose(bool disposing)
        {
            if (__Instance == IntPtr.Zero)
                return;
            global::MatrixIssue.Matrix3x3 __dummy;
            NativeToManagedMap.TryRemove(__Instance, out __dummy);
            if (__ownsNativeInstance)
                Marshal.FreeHGlobal(__Instance);
            __Instance = IntPtr.Zero;
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions