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

Crashes after dispose #622

Open
mazurekj opened this issue Feb 17, 2020 · 2 comments
Open

Crashes after dispose #622

mazurekj opened this issue Feb 17, 2020 · 2 comments

Comments

@mazurekj
Copy link

I have an issue about Vlc.DotNet.

Generic information

  • Vlc.DotNet version : 3.0.0
  • Vlc.DotNet project used : WPF
  • libvlc version : x64, nuget
  • .net version : 4.6.1
  • Project language : C#
  • Project build architecture : x64
  • Operating system : Windows 10 x64

Summary

System.AggregateException: Wyjątków zadania nie zaobserwowano ani przez oczekiwanie na zadanie, ani przez uzyskanie dostępu do jego właściwości Exception. W wyniku tego niezaobserwowany wyjątek został wywołany ponownie przez wątek finalizatora. ---> System.NullReferenceException: Odwołanie do obiektu nie zostało ustawione na wystąpienie obiektu.
w Vlc.DotNet.Core.VlcMediaPlayer.<>c__DisplayClass167_1.b__0()
w System.Threading.Tasks.Task.Execute()
--- Koniec śladu stosu wyjątków wewnętrznych ---
---> (Wyjątek wewnętrzny #0) System.NullReferenceException: Odwołanie do obiektu nie zostało ustawione na wystąpienie obiektu.
w Vlc.DotNet.Core.VlcMediaPlayer.<>c__DisplayClass167_1.b__0()
w System.Threading.Tasks.Task.Execute()<---

This exception comes out randomly, after disposing.

We initialize the control this way:
player.SourceProvider.CreatePlayer(player.VlcLibDirectory,ParseParameters(player.ViewModel.Parameters)); player.SourceProvider.MediaPlayer.Log += MediaPlayerOnLog; player.SourceProvider.MediaPlayer.Playing += MediaPlayerOnPlaying; player.SourceProvider.MediaPlayer.EncounteredError += MediaPlayerOnEncounteredError; player.SourceProvider.MediaPlayer.EndReached += MediaPlayerOnEndReached; player.SourceProvider.MediaPlayer.Play(player.ViewModel.StreamUrl);

And it is disposed this way:
`if (player.SourceProvider.MediaPlayer == null)
{
return;
}

player.SourceProvider.MediaPlayer.Log -= MediaPlayerOnLog;
player.SourceProvider.MediaPlayer.Playing -= MediaPlayerOnPlaying;
player.SourceProvider.MediaPlayer.EncounteredError -= MediaPlayerOnEncounteredError;
player.SourceProvider.MediaPlayer.EndReached -= MediaPlayerOnEndReached;

player.SourceProvider.Dispose();`

  • [ x] I confirm that my issue doesn't happen in VLC itself.
@jeremyVignelles
Copy link
Collaborator

Can you send a minimal repro on github so that I can try it locally?

@mazurekj
Copy link
Author

mazurekj commented Mar 25, 2020

Ok. After some changes in your code (VlcMediaPlayer.Events.Log.cs)

private void OnLogInternal(IntPtr data, VlcLogLevel level, IntPtr ctx, string format, IntPtr args)
        {
            if (disposed)
            {
                return;
            }
            if (this.log != null)
            {
                // Original source for va_list handling: https://stackoverflow.com/a/37629480/2663813
                var byteLength = Win32Interops._vscprintf(format, args) + 1;
                var utf8Buffer = Marshal.AllocHGlobal(byteLength);

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

                    formattedDecodedMessage = Utf8InteropStringConverter.Utf8InteropToString(utf8Buffer);
                }
                finally
                {
                    Marshal.FreeHGlobal(utf8Buffer);
                }

                string module;
                string file;
                uint? line;
                if (Manager == null)
                {
                    return;
                }
                this.Manager.GetLogContext(ctx, out module, out file, out line);

                // Do the notification on another thread, so that VLC is not interrupted by the logging
#if NETSTANDARD1_3 || NETSTANDARD2_0 || NET45
                Task.Run(() => {
                    if (disposed)
                    {
                        return;
                    }

                   this.log?.Invoke(this.myMediaPlayerInstance, new VlcMediaPlayerLogEventArgs(level, formattedDecodedMessage, module, file, line));
                });
#else
                ThreadPool.QueueUserWorkItem(eventArgs =>
                {
                    if (disposed)
                    {
                        return;
                    }
                    this.log?.Invoke(this.myMediaPlayerInstance, (VlcMediaPlayerLogEventArgs)eventArgs);
                }, new VlcMediaPlayerLogEventArgs(level, formattedDecodedMessage, module, file, line));
#endif
            }

It is now working. But now I am experiencing the issue: #625

only in cases when I try to dispose MediaPlayer and it is not rendering because of the slow speed of IP camera stream, but the player says - it is Playing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants