CallbackBase.Release() - Null reference exception
victor-david opened this issue · comments
Under certain circumstances, the CallbackBase.Release() method will throw a null reference exception because (at line 75) callback.Shadow is null and therefore the attempt to call to its Dispose() method throws.
In my case (may be others, I don't know), I was attempting to dispose of an audio effect that had not been inserted into the effect chain of the mastering voice. Example:
audioCapture = new AudioCaptureEffect();
audioCaptureEffectDescriptor = new EffectDescriptor(audioCapture);
// masteringVoice.SetEffectChain(audioCaptureEffectDescriptor);
Later at app ending:
audioCapture.Dispose();
// or
SharpDX.Utilities.Dispose(ref audioCapture);
// throws the null ref exception
If I remove the comment above, i.e:
masteringVoice.SetEffectChain(audioCaptureEffectDescriptor);
the shadow is created and Dispose works as expected. Maybe a simple check at line 75 to see if callback.Shadow is null before calling its Dispose method.
I realize I can work around this issue simply enough by always inserting the effect into the chain instead of doing so optionally later, but there might be other circumstances with other disposable objects for which the shadow doesn't get created.