Skip to content
This repository has been archived by the owner on Mar 30, 2019. It is now read-only.

Check for null reference before callback #1121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion Source/SharpDX.XAudio2/VoiceShadow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,50 +64,80 @@ public VoiceVtbl()
static private void OnVoiceProcessingPassStartImpl(IntPtr thisObject, int bytes)
{
var shadow = ToShadow<VoiceShadow>(thisObject);
if (shadow == null)
Copy link

@h1cks h1cks Feb 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coding style only comments.

Would you not use "If (Shadow != null)" and nest the logic?

Or would you also consider using and I have not tested this, so it might not be valid -

var callback = (VoiceCallback)shadow?.Callback;
callback?.OnVoiceProcessingPassStart(bytes);

only a passing question.

return;
var callback = (VoiceCallback)shadow.Callback;
if (callback == null)
return;
callback.OnVoiceProcessingPassStart(bytes);

}

static private void OnVoiceProcessingPassEndImpl(IntPtr thisObject)
{
var shadow = ToShadow<VoiceShadow>(thisObject);
if (shadow == null)
return;
var callback = (VoiceCallback)shadow.Callback;
if (callback == null)
return;
callback.OnVoiceProcessingPassEnd();

}

static private void OnStreamEndImpl(IntPtr thisObject)
{
var shadow = ToShadow<VoiceShadow>(thisObject);
if (shadow == null)
return;
var callback = (VoiceCallback)shadow.Callback;
if (callback == null)
return;
callback.OnStreamEnd();
}

static private void OnBufferStartImpl(IntPtr thisObject, IntPtr address)
{
var shadow = ToShadow<VoiceShadow>(thisObject);
if (shadow == null)
return;
var callback = (VoiceCallback)shadow.Callback;
if (callback == null)
return;
callback.OnBufferStart(address);
}

static private void OnBufferEndImpl(IntPtr thisObject, IntPtr address)
{
var shadow = ToShadow<VoiceShadow>(thisObject);
if (shadow == null)
return;
var callback = (VoiceCallback)shadow.Callback;
if (callback == null)
return;
callback.OnBufferEnd(address);
}


static private void OnLoopEndImpl(IntPtr thisObject, IntPtr address)
{
var shadow = ToShadow<VoiceShadow>(thisObject);
if (shadow == null)
return;
var callback = (VoiceCallback)shadow.Callback;
if (callback == null)
return;
callback.OnLoopEnd(address);
}

static private void OnVoiceErrorImpl(IntPtr thisObject, IntPtr bufferContextRef, int error)
{
var shadow = ToShadow<VoiceShadow>(thisObject);
if (shadow == null)
return;
var callback = (VoiceCallback)shadow.Callback;
if (callback == null)
return;
callback.OnVoiceError(bufferContextRef, new Result(error));
}
}
Expand All @@ -117,4 +147,4 @@ protected override CppObjectVtbl GetVtbl
get { return Vtbl; }
}
}
}
}