Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect marshalling of native object to managed #33

Open
UnityAlex opened this issue Sep 9, 2020 · 0 comments
Open

Incorrect marshalling of native object to managed #33

UnityAlex opened this issue Sep 9, 2020 · 0 comments

Comments

@UnityAlex
Copy link

get { return au_cv_Mat_getData_uchar(CppPtr); }

In Mat's DataByte accessor the native uchar* object is being directly assigned/returned as a byte[] without marshalling it as a managed object first. This can cause issues such as this: https://issuetracker.unity3d.com/issues/crash-while-inspecting-byteslist-values-of-a-dictionary-in-vs-debugger-when-using-arucounity-plugin

I was able to work around the crash by doing this:

[DllImport("ArucoUnityPlugin")]
      static extern IntPtr au_cv_Mat_getData_uchar(IntPtr mat);

      public byte[] DataByte
      {
        get
        {
          byte[] bytes = new byte[Total()];
          IntPtr inputBuffer = au_cv_Mat_getData_uchar(CppPtr);
          Marshal.Copy(inputBuffer, bytes, 0, (int)Total());
          return bytes;
        }
        set { au_cv_Mat_setData_uchar(CppPtr, value); }
      }

Hope this helps! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant