Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leaks on EVRPresenter when changes video source frequently #81

Open
veve178 opened this issue Jul 6, 2018 · 5 comments
Open
Labels

Comments

@veve178
Copy link

veve178 commented Jul 6, 2018

I have 4 MediaElement instances presented on 4 monitor with LAV decoder which the problem could occur on all Hardware Acceleration setting.

To reproduce the problem, first you need to have a subscribed event on the newly opened media. The video will change to other one when it is almost finished.

        private void VideoPlayer_MediaOpened(object sender, RoutedEventArgs e) {
            if (this.videoPlayer.MediaDuration < 0)
            {
            //PLAY NEXT VIDEO IN THE FOLDER
                return;
            }
            System.Timers.Timer timer = new System.Timers.Timer();
            timer.Interval = (double)(this.videoPlayer.MediaDuration/ TimeSpan.TicksPerMillisecond) * 3 - 500d;
            timer.Elapsed += TimerCallback;
            timer.AutoReset = false;  // makes it fire only once
            timer.Start(); // Start
        }


        private void TimerCallback(object sender, System.Timers.ElapsedEventArgs e) {
            this.videoPlayer.Stop();
            this.videoPlayer.Close();
            this.videoPlayer.Source = null;

            //PLAY NEXT VIDEO IN THE FOLDER
            this.videoPlayer.Source = new Uri(@path, UriKind.Absolute);
            this.videoPlayer.Play();
        }

The memory usage in the EVRPresenter64.dll keep increasing when it switched to another source.

@xmedeko xmedeko added the bug label Jul 9, 2018
@xmedeko
Copy link
Collaborator

xmedeko commented Jul 9, 2018

Thanks for the report. Does the bug appears for the VMR9 renderer? Do you need to use EVR?

I do not understand the EVR code much, so If you can fix the problem, then a PR is welcome.

@veve178
Copy link
Author

veve178 commented Jul 26, 2018

both VMR9 and EVR can produce same result.

@xmedeko
Copy link
Collaborator

xmedeko commented Jul 26, 2018

@veve178 You have written: "The memory usage in the EVRPresenter64.dll keep increasing ...". When you use VMR9, you do not use EVRPresenter64.dll - you can delete it. So, are you sure you use VMR9? If so, can you detect where is memory increasing?

@mi1124
Copy link

mi1124 commented Nov 12, 2018

Hi,

I get the following exception in D3DRenderer in SetBackBufferInternal():
System.AccessViolationException occurred. An attempt was made to read or write in the protected memory. This is often an indication that other memory is corrupted.

StackTrace:
bei MS.Win32.PresentationCore.UnsafeNativeMethods.InteropDeviceBitmap.Create(IntPtr d3dResource, Double dpiX, Double dpiY, UInt32 version, FrontBufferAvailableCallback pfnCallback, Boolean isSoftwareFallbackEnabled, SafeMILHandle& ppInteropDeviceBitmap, UInt32& pixelWidth, UInt32& pixelHeight)
bei System.Windows.Interop.D3DImage.SetBackBuffer(D3DResourceType backBufferType, IntPtr backBuffer, Boolean enableSoftwareFallback)
bei Vdi.VideoFramework.MediaPlayer.D3DRenderer.SetBackBufferInternal(IntPtr backBuffer) in D:\Sources\Repository\Main\Components\VideoFramework_2015\SourceCode\VideoFramework\MediaPlayer\D3DRenderer.cs:Zeile 387.

this exception occurs after sometime when I try playing mulitple videos .
I used [System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptionsAttribute()] on the function which was causing the AccessViolationException, but the application still crashes.
Any workaround for this exception?

@SoftwareMagicIT
Copy link

To prevent memory leak and other issues you need to close previous video before load next on same instance of player. WPF-Mediakit include close method for video resources released. Also I suggest to use gc.collect for clean garbage of .net

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

No branches or pull requests

4 participants