Vlc.DotNet icon indicating copy to clipboard operation
Vlc.DotNet copied to clipboard

Application get crash while playing multiple vlc controls.

Open SukheshMajalkar opened this issue 6 years ago • 41 comments

I have an issue / a question (pick one) about Vlc.DotNet.

Generic information

  • Vlc.DotNet version : 3.0.0
  • Vlc.DotNet project used : WinForms
  • libvlc version : (Please fill) x86 + By installing vlc version 3.0.7 and coping into libvlc folder.
  • .net version : 4.5.1
  • Project language : C#
  • Project build architecture : 32bits
  • Operating system : Windows 10

Summary

On single window while playing two vlc controls application get crash and windows event log shows me the ntdll.dll error:

Faulting application name: XtremeMediaClient.exe, version: 1.0.0.0, time stamp: 0x5d0f325a Faulting module name: ntdll.dll, version: 10.0.14393.0, time stamp: 0x57898d9d Exception code: 0xc0000374 Fault offset: 0x000d9841 Faulting process id: 0x1ea4 Faulting application start time: 0x01d5299b54163009 Faulting application path: C:\Program Files (x86)\Xtreme Media\Xtreme Media Player\XtremeMediaClient.exe Faulting module path: C:\Windows\SYSTEM32\ntdll.dll Report Id: fec9d212-b70a-49f1-865f-fa9fe14f1bae Faulting package full name: Faulting package-relative application ID:

After playing some loops it will crash.

SukheshMajalkar avatar Jun 23 '19 12:06 SukheshMajalkar

Can you share full code in a git repo so we can repro locally?

libvlc version : (Please fill) x86 + By installing vlc version 3.0.7 and coping into libvlc folder.

You should try nuget next time

mfkl avatar Jun 23 '19 12:06 mfkl

This often indicates a memory corruption or something wrong on the native side. To help us further investigate, could you share a minimal project that we can run to reproduce the issue?

jeremyVignelles avatar Jun 23 '19 12:06 jeremyVignelles

LibVlcDemo.zip In this zip i was created the application in which two vlc controls were 3 videos playing simultaneously, and put it on overnight testing, at morning i saw application got crashed and ntdll.dll error was occurred in event log. Kindly find the event log details: Faulting application name: LibVlcDemo.vshost.exe, version: 14.0.23107.0, time stamp: 0x559b788a Faulting module name: ntdll.dll, version: 10.0.17134.556, time stamp: 0x319e0a75 Exception code: 0xc0000374 Fault offset: 0x000d8529 Faulting process ID: 0x7a8 Faulting application start time: 0x01d52a95053be352 Faulting application path: D:\Share\VlcCode\LibVlcDemo - Copy\LibVlcDemo\bin\Debug\LibVlcDemo.vshost.exe Faulting module path: C:\WINDOWS\SYSTEM32\ntdll.dll Report ID: e586782e-a1c2-4b81-b531-dfa216d2e424 Faulting package full name: Faulting package-relative application ID:

Kindly help me out about this.

SukheshMajalkar avatar Jun 25 '19 07:06 SukheshMajalkar

Also while playing full hd videos d3d11.dll error also occurred in event log and application get crashed.

SukheshMajalkar avatar Jun 25 '19 13:06 SukheshMajalkar

I also have crash issues when I use multiple winforms VLC controls (wrapped in a WPF app) and I stress them (frequent play/stop)

I will try to create a simplified repro today.

srollinet avatar Jul 10 '19 06:07 srollinet

here is the repro: https://github.com/srollinet/VlcDotNetCrashIssue

In the real application, it receives affectation commands from outside, se here I simulate this behavior with multiple tasks that do random video affectations

All the useful parameters are in MainWindow.xaml.cs. You will have to change the StreamUris as they are all on a private network All the vlc related stuff is in VideoPlayer.xaml.cs

Some remarks:

  • Here the scenario is a bit exaggerated compared to the real application ;)
  • In the real application it crashes faster, with less players (usually 2x2) and with less intensive affectations
  • The real application always uses the UI thread to play and stop the players, but in the repro I had to use a different thread because otherwise it deadlocks sometimes. -> it feels a bit weird to use a different thread to deal with UI stuff

srollinet avatar Jul 11 '19 10:07 srollinet

Thanks for the repro, I hope to have a look at it soon. Please ping me if you don't hear back before monday.

jeremyVignelles avatar Jul 11 '19 10:07 jeremyVignelles

I tried your sample and I replaced the URL with 2 http urls (I don't have rtsp urls at hand to test). My streams failed and I didn't see any crash. I'll test more touroughly later. Can you try with files instead of streams and see if it fails too?

jeremyVignelles avatar Jul 11 '19 19:07 jeremyVignelles

Thanks for the feedback. I will try with files as soon as possible.

Regarding the deadlock issue, is it normal that I have to interact with the player from another thread or is it a bug?

srollinet avatar Jul 12 '19 06:07 srollinet

Not sure, it might be an issue with your app. Do you know at which line it deadlocks? Be careful : When Play() is called with your timer, you are already on the main thread. I'm not sure you need to switch to the main thread there: https://github.com/srollinet/VlcDotNetCrashIssue/blob/de0ef867ce444ab78e2fe30ddfe8a380a54f85f8/VlcCrashRepro/MainWindow.xaml.cs#L84

Where is the VideoPlayer.Stop() method called?

jeremyVignelles avatar Jul 12 '19 07:07 jeremyVignelles

Stop is called from the outside and is also called from the main thread so there is no concurrent calls.

Yes, it is voluntary that the timer switch to the main thread, because in the real app the ViewModel is always used from the main thread (It does more UI stuff so I need to be on the UI thread)

What feels weird is that we have to interact with the player in another thread otherwise it may deadlock. This is not very common in a desktop application.

srollinet avatar Jul 12 '19 08:07 srollinet

any solution on ntdll.dll error and application got a crash issue ?

SukheshMajalkar avatar Jul 15 '19 08:07 SukheshMajalkar

Didn't had time to look at it, please ping me on wednesday if I don't reply until then

jeremyVignelles avatar Jul 15 '19 09:07 jeremyVignelles

Can you try with files instead of streams and see if it fails too?

It doesn't seem to crash when using files

srollinet avatar Jul 15 '19 16:07 srollinet

Didn't had time to look at it, please ping me on wednesday if I don't reply until then

Thank you for the quick reply.

SukheshMajalkar avatar Jul 16 '19 04:07 SukheshMajalkar

@srollinet : Thanks for the repro. I was able to see it crash. It makes me think of a native crash, i'll try to reproduce it in https://github.com/jeremyVignelles/TestLibvlcNative in the next few days, but I need to be at work to have access to rtsp cameras.

While I will try to find the issue on my free time, you can still help by trying one or more of these things:

  • Try to create several rtsp streams with VLC, and see if that crashes the same way. Here is a sample command line;
vlc.exe -I dummy "01_llama_drama_half.mp4" :sout=#gather:rtp{sdp=rtsp://:8555/} :sout-keep --loop
  • Try to reproduce with other kind of streams (http, HLS, udp streams, other codecs...)
  • Try reducing the amount of code needed to reproduce the issue.
  • Try eliminating the randomness, does it happen in reproducible conditions, like a really short timer?

Another tip for next time : Please use the libvlc in NuGet, it's easier to install, and we don't need to wonder which version you used.

jeremyVignelles avatar Jul 16 '19 07:07 jeremyVignelles

@srollinet : Thanks for the repro. I was able to see it crash. It makes me think of a native crash, i'll try to reproduce it in https://github.com/jeremyVignelles/TestLibvlcNative in the next few days, but I need to be at work to have access to rtsp cameras.

While I will try to find the issue on my free time, you can still help by trying one or more of these things:

  • Try to create several rtsp streams with VLC, and see if that crashes the same way. Here is a sample command line;
vlc.exe -I dummy "01_llama_drama_half.mp4" :sout=#gather:rtp{sdp=rtsp://:8555/} :sout-keep --loop
  • Try to reproduce with other kind of streams (http, HLS, udp streams, other codecs...)
  • Try reducing the amount of code needed to reproduce the issue.
  • Try eliminating the randomness, does it happen in reproducible conditions, like a really short timer?

Ok I will make several try these next days and I come back to you with the results

Another tip for next time : Please use the libvlc in NuGet, it's easier to install, and we don't need to wonder which version you used.

I think I use it from Nuget no? Or am I doing something wrong? https://github.com/srollinet/VlcDotNetCrashIssue/blob/master/VlcCrashRepro/VlcCrashRepro.csproj#L108 https://github.com/srollinet/VlcDotNetCrashIssue/blob/master/VlcCrashRepro/VideoPlayer.xaml.cs#L23

srollinet avatar Jul 16 '19 08:07 srollinet

Oh you're right, I was mislead by the fact that Visual Studio showed me a list of plugins and libvlc.dll... These files doesn't appear when using a SDK-style project, hence the confusion...

jeremyVignelles avatar Jul 16 '19 08:07 jeremyVignelles

What about playing multiple vlc controls crash?

SukheshMajalkar avatar Jul 17 '19 07:07 SukheshMajalkar

Nothing more than yesteday, will try to continue in the next few days, but I'm nquite busy at work and getting home late.

jeremyVignelles avatar Jul 17 '19 07:07 jeremyVignelles

@jeremyVignelles Thank you for your response.

SukheshMajalkar avatar Jul 17 '19 07:07 SukheshMajalkar

I simplified your code while still crashing.

You can see the work in progress here : https://github.com/jeremyVignelles/VlcDotNetCrashIssue

jeremyVignelles avatar Jul 17 '19 13:07 jeremyVignelles

Just tried your version with local rtsp streams (from VLC) No crashes for now, but sometimes threads are blocked here in VlcManager.cs

public void Stop(VlcMediaPlayerInstance mediaPlayerInstance)
{
  if ((IntPtr) mediaPlayerInstance == IntPtr.Zero)
    throw new ArgumentException("Media player instance is not initialized.");
  this.myLibraryLoader.GetInteropDelegate<Stop>()((IntPtr) mediaPlayerInstance); //<---------
}

so all the "producers" are quickly blocked on the lock section

srollinet avatar Jul 17 '19 17:07 srollinet

How do you tell that threads are blocked? app becomes unresponsive?

Do you reproduce any of the bugs if you remove the player.Stop() line?

jeremyVignelles avatar Jul 17 '19 18:07 jeremyVignelles

How do you tell that threads are blocked? app becomes unresponsive?

The app is still responsive because everything is done on background threads. But every time I stop the debugger, most of the tasks are blocked on lock (_vlcControlLock) and 1-2 tasks are blocked in VlcManager.cs

This is not frequent, but it happened a few times.

Do you reproduce any of the bugs if you remove the player.Stop() line?

I will try now. But the problem when not stopping the player is that the old stream is still playing while the new one is loading.

In our application, we have an overlay with additional infos. So we don't want to display infos from a new camera on the old camera stream.

srollinet avatar Jul 17 '19 18:07 srollinet

So we don't want to display infos from a new camera on the old camera stream.

You could switch your info when the Playing event is triggered.

That's weird you don't reproduce with my code, I'll retry tomorrow.

Do you know if the crash happens with a specific brand of camera or with all you tried?

jeremyVignelles avatar Jul 17 '19 18:07 jeremyVignelles

That's weird you don't reproduce with my code, I'll retry tomorrow.

Could it be hardware related? Now I am at home, I have a desktop with a dedicated graphic card. When I am at work I use a laptop, and the target hardware is a NUC. So the conditions are not the same.

Also at home I have no cameras so I test with streams from VLC. I will test your code tomorrow at work

Do you know if the crash happens with a specific brand of camera or with all you tried?

I will check tomorrow, but in our dev env we have mostly Axis cameras

srollinet avatar Jul 17 '19 18:07 srollinet

My main problem is not that a player crashes, it is that the whole app crashes.

But if we can't reproduce it and if it is not possible to catch the exception somehow, I can change the application design and create each player in a different process, so if one of the player crashes, I can restart it.

srollinet avatar Jul 17 '19 19:07 srollinet

Could it be hardware related? Now I am at home, I have a desktop with a dedicated graphic card. When I am at work I use a laptop, and the target hardware is a NUC. So the conditions are not the same.

It could be hardware related, but I have a fast computer at work and it did crash. It could also be network related, stream related or anything else. In fact, anything that could cause two actions happening in the wrong order is a suspect.

Also at home I have no cameras so I test with streams from VLC. I will test your code tomorrow at work

That could also potentially explain why it doesn't crash... The stream is different.

My main problem is not that a player crashes, it is that the whole app crashes.

My guess is that the whole app crashes because of a native crash (bad pointer usage for example) in one of the player. My goal is currently to prove that the crash isn't caused by Vlc.DotNet and that it can be reproduced with only libvlc, but for that I need to strip down the code to its minimum before translating it to C/C++. Or maybe, in the process, I will find something weird in Vlc.DotNet that can cause the issue.

Anyway, you can't go to libvlc's trac and tell them there is a bug without something they can reproduce on their machine.

But if we can't reproduce it and if it is not possible to catch the exception somehow,

You can't catch native crashes by design. When an invalid pointer is accessed, the OS protects itself by shutting down the app.

I can change the application design and create each player in a different process, so if one of the player crashes, I can restart it.

You could do that, and that would be better for stability. However, keep in mind that you wouldn't be able to gather all videos in the same window after that...

jeremyVignelles avatar Jul 17 '19 19:07 jeremyVignelles

I can change the application design and create each player in a different process, so if one of the player crashes, I can restart it.

You could do that, and that would be better for stability. However, keep in mind that you wouldn't be able to gather all videos in the same window after that...

It's not an issue in my case because the application is always full screen with x players, so I can open x windows and give them their size and location.

srollinet avatar Jul 17 '19 19:07 srollinet