Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Commit

Permalink
Null check in fire-and-forget logging action.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Provost authored and jeremyVignelles committed May 6, 2020
1 parent 8375b4c commit 9afe889
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Vlc.DotNet.Core/VlcMediaPlayer/VlcMediaPlayer.Events.Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ private void OnLogInternal(IntPtr data, VlcLogLevel level, IntPtr ctx, string fo
var utf8Buffer = Marshal.AllocHGlobal(byteLength);

string formattedDecodedMessage;
try {
try
{
Win32Interops.vsprintf(utf8Buffer, format, args);

formattedDecodedMessage = Utf8InteropStringConverter.Utf8InteropToString(utf8Buffer);
}
finally
Expand All @@ -78,11 +78,16 @@ private void OnLogInternal(IntPtr data, VlcLogLevel level, IntPtr ctx, string fo

// Do the notification on another thread, so that VLC is not interrupted by the logging
#if NETSTANDARD1_3 || NETSTANDARD2_0 || NET45
Task.Run(() => this.log(this.myMediaPlayerInstance, new VlcMediaPlayerLogEventArgs(level, formattedDecodedMessage, module, file, line)));
Task.Run(() =>
{
if(this.log != null)
this.log(this.myMediaPlayerInstance, new VlcMediaPlayerLogEventArgs(level, formattedDecodedMessage, module, file, line));
});
#else
ThreadPool.QueueUserWorkItem(eventArgs =>
{
this.log(this.myMediaPlayerInstance, (VlcMediaPlayerLogEventArgs)eventArgs);
if (this.log != null)
this.log(this.myMediaPlayerInstance, (VlcMediaPlayerLogEventArgs)eventArgs);
}, new VlcMediaPlayerLogEventArgs(level, formattedDecodedMessage, module, file, line));
#endif
}
Expand Down

0 comments on commit 9afe889

Please sign in to comment.