Search Unity

Unity 5.3.1p2 IL2CPP fixing #752153 broke my code

Discussion in 'iOS and tvOS' started by Deleted User, Jan 11, 2016.

  1. Deleted User

    Deleted User

    Guest

    I'm using native plugins that use [In, Out] on an array of floats. Everything has been working fine for months, until 5.3.1p2. Now, my code is breaking when I try to PInvoke the following function:

    Code (csharp):
    1.  
    2. [DllImport(libName, CallingConvention=CallingConvention.Cdecl)]
    3. private static extern int Native_GetData([In, Out] float[] output, int max_count);
    4.  
    5. // ....
    6.  
    7. float[] data = new float[10];
    8. Native_GetData(data, 10); // error, see below
    9.  
    at runtime, I land here:

    Code (csharp):
    1.  
    2. inline void il2cpp_codegen_marshal_free(void* ptr) {
    3.     il2cpp::vm::PlatformInvoke::MarshalFree(ptr);   //  [1]
    4. }
    5.  
    [1] malloc: *** error for object 0x10a822c20: pointer being freed was not allocated

    I'm assuming that this is what did it:

    http://issuetracker.unity3d.com/iss...ethod-for-array-parameters-with-out-attribute

    Anyone else with this issue?

    Thanks


    *edit*
    Correction, this issue was supposedly fixed in 5.3.1p1 not p2.


     
    Last edited by a moderator: Jan 11, 2016
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    @Al Bundy

    Do you happen to have a call stack for the call to il2cpp_codegen_marshal_free that causes the error? I think that I know where the problematic call will be in the generated code, but I would like to confirm that. Also, how is the array allocated in native code? Thanks.
     
  3. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Actually, looking at this again, it seems that the array is not allocated in native code, sorry. Let me see if we can reproduce this problem here.
     
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Yes, the bug is entirely on our side. I've been able to reproduce it, and I'll work on getting a fix now. Sorry for the inconvenience. Thanks for reporting this!
     
  5. Deleted User

    Deleted User

    Guest

    Awesome! Thanks for the quick reply =D
     
  6. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Thanks for reporting it. The fix looks like it will land in 5.3.1p4.