Avoid Unity Editor crash when a .NET exception is thrown from a LibVLC event handler
Summary
Calling MediaPlayer.Stop(), then MediaPlayer.Dispose(), under some specific conditions, will freeze Unity and require you to process-kill it. I am not yet certain what conditions cause this bug, but it happens 100% of the time in this example, and 0% of the time on MinimalPlayback.cs, which uses essentially identical code to dispose of the player.
Minimal project and steps to reproduce
- Clone this repo: https://gitlab.com/brisingre/vlc-unity-bugs
- Import a recent development version of VLC Unity (I can provide the specific one I'm using if needed)
- Open the "131 DestroyPlayer Freeze" scene
- Press play in Unity
- Press DestroyPlayer (FREEZE!) and Unity will freeze.
- When you restart Unity, you might see some messages like this. If you click Cancel Unity will start.

- Pressing SafeDestroyPlayer (No Freeze) will destroy the player without freezing unity.
What is the current bug behavior?
This example freezes Unity every time. Calling Stop() before Dispose() appears to be the source of the issue.
What is the expected correct behavior?
Calling Stop() before Dispose() is apparently correct (it is in the example) and it works fine there. It should work fine here too.
Does it work on other plaforms? Does it work with the official VLC apps?
Right now VLC for Unity only supports one platform. Certainly VLC works fine on Windows 7.
Environment
- OS: Windows
- Version 10 LTSC (Sorry!!!)
- Device: PC
- LibVLC version and architecture 4.0.0 x64
- LibVLCSharp version Not quite sure how to check this, sorry.
- VLC Unity plugin [Some development version! @mfkl sent it to me on discord.]
- Scripting backend used Mono
Possible fixes
Not calling Stop() before Dispose() fixes the issue, although I expect there is a reason the example has it, and removing it may cause other problems.
Calling Stop() before Dispose() is fine in MinimalPlayback.cs, so something else must be different about this sample. I have no idea what the critical difference might be. (This sample's taken with minimal modification from my project, it wasn't written specifically to produce this.)

