Search Unity

[Possible bug] OnAudioFilterRead freezes editor (2019.0.1)

Discussion in 'Linux' started by willemsenzo, Aug 16, 2019.

  1. willemsenzo

    willemsenzo

    Joined:
    Nov 15, 2012
    Posts:
    585
    Why does this code work perfectly fine in Unity 5 (I asked a friend to test), but it freezes my editor in 2019.0.1f2? I can't wrap my head around this. The Oscillator class implements a wavetable and returns a float between -1 and 1 when the Calculate function is called. I can recall using this same code on older versions of Unity (all in Windows) and it always just worked, but somehow in Linux it fails.

    Code (CSharp):
    1. [RequireComponent(typeof(AudioSource))]
    2. public class SoundPlayer
    3. {
    4.     public Oscillator[] oscillators[3];
    5.     private AudioSource audioSource;
    6.     private float currentData = 0f;
    7.  
    8.     private void Start()
    9.     {  
    10.         audioSource = gameObject.GetComponent<AudioSource>();
    11.     }
    12.  
    13.     void OnAudioFilterRead(float[] data, int channels)
    14.     {
    15.         for (int i = 0; i < data.Length; i++)
    16.         {
    17.             currentData = 0;
    18.  
    19.             for (int j = 0; j < oscillators.Length; j++)
    20.             {
    21.                 currentData += oscillators[j].Calculate(counter, 44100);
    22.             }
    23.  
    24.             counter++;
    25.  
    26.             data[i] = currentData;
    27.         }
    28.     }
    29. }
     
  2. willemsenzo

    willemsenzo

    Joined:
    Nov 15, 2012
    Posts:
    585
    After upgrading to 2019.3.0a12 I can confirm it was a bug and my code is working like it should with no freezes. Still not sure what was wrong in the other version but it definitely was a bug.
     
  3. Tak

    Tak

    Joined:
    Mar 8, 2010
    Posts:
    1,001
    On Linux, we were previously using a very small stack size on the audio mixer thread, making it very easy to get a crash or stack overflow in OnAudioFilterRead.
    This has been changed in Unity 2019.2.
     
  4. willemsenzo

    willemsenzo

    Joined:
    Nov 15, 2012
    Posts:
    585
    Thanks for the update, after upgrading this problem was solved.
     
    PixelJ likes this.