Search Unity

iOS crash: malloc: *** error for object XXXX: pointer being freed was not allocated

Discussion in 'iOS and tvOS' started by justdizzy, Mar 20, 2018.

  1. justdizzy

    justdizzy

    Joined:
    Mar 8, 2016
    Posts:
    89
    I am using https://github.com/miyabi/unity-swift plugin to call a Swift audio conversion method. This is working fine, except that when the Swift code returns it's string, the Unity generated C++ code throws the
    error:

    malloc: *** error for object XXXX: pointer being freed was not allocated

    from the line (in Bulk_Assembly-CSharp-firstpass_0.cpp):

    il2cpp_codegen_marshal_free(returnValue);

    If I comment out that line the error is no longer thrown and there does not seem to be any leak. My question is, can I flag my code somehow before building so that this line is automatically omitted? Otherwise I have to manually find it to comment it out as the audio conversion is a rarely used functionality.

    Here is the C# code:

    using System.Runtime.InteropServices;

    public class AudioConverter {
    #if UNITY_IOS && !UNITY_EDITOR
    [DllImport("__Internal")]
    private static extern string _swift_TryConvertAudio(string message);
    #endif

    // Use this method to call AudioConverter.swiftMethod() in AudioConverter.swift
    // from other C# classes.
    public static string TryConvertAudio(string dirPath) {
    #if UNITY_IOS && !UNITY_EDITOR
    return _swift_TryConvertAudio(dirPath);
    #endif
    return "[\"Platform Unsupported\"]";
    }
    }


    Here is a screenshot of the crash in action, for stack examination.
    Screen Shot 2018-03-19 at 5.30.00 PM.png
     
    lewentoral likes this.