private void _killDecoder() { bool resFreeDec = false; bool resFreeCfg = false; bool resFreeTxf = false; MixCastAV.freestopAudioDecodeAsync(audAsyncDec); System.Threading.Thread.Sleep(2); //untested amount of sleep time in ms needed to avoid race condition audAsyncDec = IntPtr.Zero; //free the decoder if (audDec != IntPtr.Zero) { resFreeDec = MixCastAV.freeAudioDecodeContext(audDec) == 0 ? true : false; } audDec = IntPtr.Zero; //free the data config if (cfgAudDec != IntPtr.Zero) { resFreeCfg = MixCastAV.freeAudioCfg(cfgAudDec) == 0 ? true : false; } cfgAudDec = IntPtr.Zero; //free the transformer if (aTxfDec != IntPtr.Zero) { resFreeTxf = MixCastAV.freeAudioTransform(aTxfDec) == 0 ? true : false; } aTxfDec = IntPtr.Zero; if (resFreeDec == false || resFreeCfg == false || resFreeTxf == false) { Debug.LogError("Error Freeing Audio Device. " + audDec); } }