objectdisposelibvlcsharp

Memory Access Violation disposing libvlcsharp objects from a task


Link to full sample app C# Winform application built in Visual Studio 2019 libvlcsharp runtime version v4.0.30319 version 3.4.4.0

I built a simpler application that has the same problem as one that is currently deployed.

Here's where the code gets the player started:

videoView1.MediaPlayer.Play(new Media(_libVLC, URI,FromType.FromLocation));

Here's the cleanup code snip:

  videoView1.MediaPlayer.Stop();
  videoView1.MediaPlayer.Dispose();
  videoView1.Dispose();
  //dispose glibvlc at higher level

The MediaPlayer dispose works OK no errors. However, videoview dispose causes a Memory Access Violation. I know this isn't normal because I built a simple c# application without using a task to dispose and clean up the objects and that worked just fine.

However the application I'm trying to debug has one thread per stream that is being displayed to manage setting up and shutting down each connection.

If the code just calls dispose on the mediaplayer and does not dispose the videoview object then the object that contains the libvlcsharp objects causes a Memory Access Violation when it gets disposed.

If I don't dispose of the MediaPlayer object any subsequent object dispose calls work OK. I have verified that this leaks memory.

The Ask function asks if the user wants to exit the program or kill the current player and build and start it again.

Here's the c# sample ask function.

public void Ask()
        {
            while (true)
            {
                DialogResult r = MessageBox.Show("Dispose and Start Again?", "Memory Access Violation Test", MessageBoxButtons.OKCancel);
                if (r == DialogResult.OK)
                {
                    videoView1.MediaPlayer.Stop();
                    videoView1.MediaPlayer.Dispose();
                    videoView1.Dispose();
                    StartVideo();
                }
                else
                {
                    Invoke(new Action(() => this.Close()));                   
                }
            }

        }

Solution

  • To fix problem upgrade to version 3.6.1.0 for both libvlcsharp and libvlcwinforms.winforms