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

crash on excessive video switching #621

Open
GeorgeMaharis123 opened this issue Feb 11, 2020 · 1 comment
Open

crash on excessive video switching #621

GeorgeMaharis123 opened this issue Feb 11, 2020 · 1 comment

Comments

@GeorgeMaharis123
Copy link

GeorgeMaharis123 commented Feb 11, 2020

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

Generic information

  • Vlc.DotNet version : 3.0.0-develop294
  • Vlc.DotNet project used : WinForms
  • libvlc version : x86 & x64, by downloading from VLC FTP, testet with version 3.0.2, 3.0.6, 3.0.8
  • .net version : 4.7
  • Project language : C#
  • Project build architecture : AnyCPU
  • Operating system : Windows 10 x64

Summary

I'm having issues with fast video switching/loading and stopping. My application plays a video (.mp4) for a given amount of time and then stops and shows nothing for the same amount of time and then restarts this loop. For example with this time set to 10 seconds, it will play the video for 10 sec, then blank for 10 sec, then again the video for 10 sec. Until it is stopped by the user or in this case a crash. The crash happens (with the play time set to 10sec) after 1-2 hours of looping. If the time is set to 1.5 seconds, it will crash in about 15 minutes.

I reported this bug to vlc/videolan: https://trac.videolan.org/vlc/ticket/22427 . Turns out the problem is not directly in VLC but in usage of VLC. As tigros999 commented on the issue, it can be bypassed in VLC.dotNet

I was able to reproduce this bug while letting the app run from VS debug for a long time breaking on all exceptions.
The exception was: Managed Debugging Assistant 'LoaderLock?'
Message=Managed Debugging Assistant 'LoaderLock?' : 'Attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain? or image initialization function since doing so can cause the application to hang.'

It was on myVlcInstance = new VlcInstance?(this, myLibraryLoader.GetInteropDelegate?<CreateNewInstance?>().Invoke(utf8Args.Length, utf8Args)); of Vlc.DotNet?.Core.Interops\VlcManager?.cs. Continuing execution got the C++ crash and app closed.

So from that I found this: ​https://stackoverflow.com/a/31322244/990618

VlcManager?.cs becomes:

...
private VlcLibraryLoader myLibraryLoader;
private VlcInstance myVlcInstance;
...
	ThreadStart threadRef = new ThreadStart(() =>
	{
		this.myLibraryLoader = VlcLibraryLoader.GetOrCreateLoader(dynamicLinkLibrariesPath);
	});
	Thread myThread = new Thread(threadRef);
	myThread.IsBackground = true;
	myThread.Start();
	myThread.Join();
...
	threadRef = new ThreadStart(() =>
	{
		myVlcInstance = new VlcInstance(this, myLibraryLoader.GetInteropDelegate<CreateNewInstance>().Invoke(utf8Args.Length, utf8Args));
	});
	myThread = new Thread(threadRef);
	myThread.IsBackground = true;
	myThread.Start();
	myThread.Join();                
@jeremyVignelles
Copy link
Collaborator

Please send me a minimal reproducing sample so I can check this out locally.

The code that was suggested doesn't feel like a proper fix for me:

  • Are you really destroying/recreating media player each time you need one? This method is only called when creating a new player. Calling Stop() and Play() again should be enough for your use case.
  • The fact that this happens randomly makes me think about some race condition/memory leak somewhere. Creating a thread can probably introduce a latency in the code, which would "save" you from the crash, but it's not a real fix.
  • If it was a deadlock issue, then you could do that kind of code around your "new VlcMediaPlayer" code, and see if that fixes anything.

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