hudec117 / Mpv.NET-lib-

.NET embeddable video/media player based on mpv for WinForms and WPF
MIT License
138 stars 36 forks source link

App fails if Dispose is called and new instance of MPV is created after #37

Open marpit opened 3 years ago

marpit commented 3 years ago

Mpv.NET (lib) Version 2.0.0.0

Describe the bug I was created two windows, first window contains button, which create new window with new instance of mvp player. If this window is closed, i call stop playing and dispose method. If I click to button in first window again, application fails with error:

[cplayer] Set property: pause="yes" -> 1 [cplayer] Run command: loadfile, flags=64, args=[url="rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov", flags="replace", options=""] [global] config path: 'watch_later' -> '-' [cplayer] Running hook: ytdl_hook/on_load [ytdl_hook] ytdl:// hook [cplayer] Set property: pause="no" -> 1 [ytdl_hook] not a ytdl:// url [ffmpeg] Opening rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov [ffmpeg] resize stream to 4096 bytes, drop 0 bytes [ffmpeg] Stream opened successfully. [demux] Trying demuxers for level=request. [demux] Trying demuxer: lavf (force-level: request) [lavf] Found 'rtsp' at score=100 size=0 (forced). [lavf] Broken FFmpeg RTSP API => not setting timeout. [ffmpeg] tcp: Starting connection attempt to 34.227.104.115 port 554 [ffmpeg] tcp: Successfully connected to 34.227.104.115 port 554 [ffmpeg/demuxer] rtsp: SDP: [ffmpeg/demuxer] v=0 [ffmpeg/demuxer] o=- 603021113 603021113 IN IP4 34.227.104.115 [ffmpeg/demuxer] s=BigBuckBunny_115k.mov [ffmpeg/demuxer] c=IN IP4 34.227.104.115 [ffmpeg/demuxer] t=0 0 [ffmpeg/demuxer] a=sdplang:en [ffmpeg/demuxer] a=range:npt=0- 596.48 [ffmpeg/demuxer] a=control:* [ffmpeg/demuxer] m=audio 0 RTP/AVP 96 [ffmpeg/demuxer] a=rtpmap:96 mpeg4-generic/12000/2 [ffmpeg/demuxer] a=fmtp:96 profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3;config=1490 [ffmpeg/demuxer] a=control:trackID=1 [ffmpeg/demuxer] m=video 0 RTP/AVP 97 [ffmpeg/demuxer] a=rtpmap:97 H264/90000 [ffmpeg/demuxer] a=fmtp:97 packetization-mode=1;profile-level-id=42C01E;sprop-parameter-sets=Z0LAHtkDxWhAAAADAEAAAAwDxYuS,aMuMsg== [ffmpeg/demuxer] a=cliprect:0,0,160,240 [ffmpeg/demuxer] a=framesize:97 240-160 [ffmpeg/demuxer] a=framerate:24.0 [ffmpeg/demuxer] a=control:trackID=2 [ffmpeg/demuxer] [ffmpeg/demuxer] rtsp: setting jitter buffer size to 0 [ffmpeg/demuxer] rtsp: setting jitter buffer size to 0 [lavf] Could not set AVOption tls_verify='0' [lavf] Could not set AVOption icy='1' [demux] Detected file format: rtsp (libavformat) [cplayer] Opening done: rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov [cplayer] Running hook: ytdl_hook/on_preloaded [lavf] select track 0 [lavf] select track 1 [cplayer] (+) Video --vid=1 (h264 240x160) [cplayer] (+) Audio --aid=1 (aac 2ch 12000Hz) [display-tags] File tags: [display-tags] Title: BigBuckBunny_115k.mov [vo/gpu] Probing for best GPU context. [vo/gpu/d3d11] Initializing GPU context 'd3d11' [vo/gpu/d3d11] Using Direct3D 11 feature level 12_1 [vo/gpu/d3d11] Device Name: NVIDIA GeForce GTX 1650 [vo/gpu/d3d11] Device ID: 10de:1f82 (rev a1) [vo/gpu/d3d11] Subsystem ID: 1458:3fca [vo/gpu/d3d11] LUID: 000000000000bdda [vo/gpu/d3d11] Initializing SPIR-V compiler 'shaderc' [vo/gpu/d3d11] Using Direct3D 11.1 runtime [vo/gpu/d3d11] Maximum Texture2D size: 16384x16384 [vo/gpu/d3d11] D3DCompiler version: 10.0.17134.1 [vo/gpu/win32] unable to create window! [vo/gpu/win32] uninit [vo/gpu/opengl] Initializing GPU context 'angle' [vo/gpu] Failed to load LIBEGL.DLL The program '[8356] XYZ.exe' has exited with code -1073741819 (0xc0000005) 'Access violation'.

This is problem with secondly creation of window with MPV player. If I does not call dispose methos, all is works, but there is memory leak.

Expected behavior I can call dispose method and create new instance of MPV after.

sudongg commented 3 years ago

I also encountered this problem. The previous problem was a crash after Dispose. After the 1.2.0 version was repaired, this new problem appeared, and a new player instance could not be generated after Dispose.

This problem can be easily reproduced. Copy the code to MainWindow.xaml.cs of the Mpv.NET.WPFExample project. After Dispose, a new player instance will inevitably crash.

    public MainWindow()
        {
            InitializeComponent();

            test();
        }

        async void test()
                {
            player = new MpvPlayer(PlayerHost.Handle)
            {
                Loop = true,
                Volume = 50
            };
            player.Load("E:\\1.mp4");
            player.Resume();

            await Task.Delay(5000);

            player.Dispose();

            await Task.Delay(1000);

            test();
        }
solaris-83 commented 2 years ago

Apparently this won't be fixed. Before moving to another player, is there a known workaround? In my application I have to create many instances but not being able to dispose them is leading my application to crash.

cdupetit commented 1 year ago

Hello @hudec117, Any news about this bug ? Thx

hudec117 commented 1 year ago

Hello, as per the README, this project is not being maintained, sorry!