Error executing instance->m_Sound->unlock

Since we updated Unity to 5.1.1f1, we encounter this error that never showed up before:

It leads to this part of the code:

    int newOffset = Microphone.GetPosition(selectedDevice);
    int nbSamplesToRetrieve;
    if (newOffset < sampleOffset)
        nbSamplesToRetrieve = newOffset + GetComponent<AudioSource>().clip.samples - sampleOffset;
    else
        nbSamplesToRetrieve = newOffset - sampleOffset;
    float[] samples = new float[nbSamplesToRetrieve];
    float sampleRate = GetComponent<AudioSource>().clip.frequency;

    GetComponent<AudioSource>().clip.GetData(samples, sampleOffset);

It still seems to work fine, but the cosole is spammed with this error and it becomes hard to debug on mobile platforms.

I’m getting this error as well, did you ever find a solution to this?

Any solutions?

We’re using 5.1.4f and seeing this issue a lot on user devices (iOS).

Anyone know if it is still occurring in newer versions of Unity?

I am having the same problem.
I am kind of “solve it” declaring the buffer float[ ] array

float[] audioBuffer = new float[audioSource.clip.samples * audioSource.clip.channels];

Assuming that I have just one channel, the dimension is frequency * seconds, the parameters that you use when you call Microphone.Start(). (For example 44100Hz * 10sec)

If I put a bigger number I get a warning that that number is bigger than 441000. If I put a calculated length (like you) I get your same error.

Now I am trying to work out to see if the program returns good results. But at least I can move on

how to catch this exception ?
i cant catch it in code !!!