Adding signal DSP causes starvation

I’m getting the starvation warning from the following code run in unity specifically on ending playmode. No actual audio needs to be played.


using System;
using FMOD;
using FMODUnity;
using UnityEngine;

class ExactExample : MonoBehaviour
{
  private DSP mCaptureDSP;
  private uint mBufferLength;
  private int mChannels = 0;
  
  void Start()
  {
    
    DSP_DESCRIPTION desc = new DSP_DESCRIPTION
    {
      numinputbuffers  = 1,
      numoutputbuffers = 1,
      // most other callbacks will not produce the starvation warning
      // although process callback fires a raw exception even when empty
      read             = CaptureDSPReadCallback 
    };

    RuntimeManager.CoreSystem.getMasterChannelGroup( out var masterCG );
    RuntimeManager.CoreSystem.createDSP( ref desc, out mCaptureDSP );
    masterCG.addDSP( 0, mCaptureDSP );
  }

  [AOT.MonoPInvokeCallback( typeof(DSP_READ_CALLBACK) )]
  static RESULT CaptureDSPReadCallback( ref DSP_STATE dsp_state, IntPtr inbuffer, IntPtr outbuffer, uint length, int inchannels, ref int outchannels )
  {
    return RESULT.OK;
  }

  private void OnDisable()
  {
    if( mCaptureDSP.hasHandle() )
    {
      if( RuntimeManager.CoreSystem.getMasterChannelGroup( out var channelGroup ) == RESULT.OK ) 
        channelGroup.removeDSP( mCaptureDSP );
      
      mCaptureDSP.release();
      mCaptureDSP.clearHandle();
    }
  }
}

If the read callback is set, the warning will fire when exiting playmode.

I’ve tried a bunch of variations. None will prevent the warning on shutdown.

Worth noting that assigning the process callback will throw a marshal type exception and lock the editor:


  [AOT.MonoPInvokeCallback( typeof(DSP_PROCESS_CALLBACK) )]
  private RESULT ProcessCallback( ref DSP_STATE dsp_state, uint length, ref DSP_BUFFER_ARRAY inbufferarray, ref DSP_BUFFER_ARRAY outbufferarray, bool inputsidle, DSP_PROCESS_OPERATION op )
  {
    return RESULT.OK;
  }

.....
MarshalDirectiveException: Structure field of type Int32[] can't be marshalled as LPArray
  at (wrapper native-to-managed) ExactExample.ProcessCallback(FMOD.DSP_STATE&,uint,FMOD.DSP_BUFFER_ARRAY&,FMOD.DSP_BUFFER_ARRAY&,int,FMOD.DSP_PROCESS_OPERATION)

Super annoying.

Am I doing something incredibly wrong here or is this just a bug in fmod’s unity api?

NOTE: Tested with an older project and the starvation warning does not happen with 2.02.15 it does happen with 2.02.22.

This is a crosspost in the hopes of getting an actual response.

Hi,

I’ve been able to reproduce both issues on my end: the starvation warning is likely benign and safe to ignore, but the process callback throwing MarshalDirectiveException is more concerning. Unfortunately I don’t have a workaround for the latter at present, but I’ve passed on both issues to the development team to investigate further.

thank you for checking in on this, is there a public bug tracker I can follow to know when this has been resolved?

No problem! Unfortunately we don’t have a public-facing bug tracker. If you’d like to keep up to date with the latest release and fixes, you can subscribe to our newsletter, which you can do from the footer of any of our webpages besides the forum. Our FMOD Engine revision history doc should contain a note about the fix when it ships as well.