Disposing of MediaPlayer on iOS causes the app to freeze in LibVLCSharp.Forms
Summary
When attempting to call dispose on the MediaPlayer before leaving a page, the app hangs. This only occurs on iOS, on Android the dispose function works correctly. Failure to call the dispose function results in a large memory leak, so that is not an option.
Minimal project and steps to reproduce
This branch on GitHub shows the issue: https://github.com/NickCRowork/VLCDisposeError
Click on Open Video, wait about 10-20 seconds for the video to finish. The app will then hang on iOS. The app is supposed to close the page, as can be seen when using Android.
What is the current bug behavior?
The app hangs when the video ends.
What is the expected correct behavior?
The app closes the video page when the video ends.
Does it work on other plaforms? Does it work with the official VLC apps?
Works properly on Android.
Relevant logs and/or screenshots
[0:] waiting decoder fifos to empty
[0:] killing decoder fourcc `h264'
[0:] removing module "avcodec"
[0:] saving a free vout
[0:] reusing provided vout
[0:] killing decoder fourcc `mp4a'
[0:] removing module "avcodec"
[0:] removing module "ugly"
[0:] removing module "ebur128"
[0:] removing module "scaletempo"
[0:] keeping audio output
[0:] removing module "float_mixer"
[0:] removing module "mp4"
[0:] freeing all memory
[0:] Program doesn't contain anymore ES
[0:] removing module "record"
[0:] removing module "prefetch"
[0:] removing module "access"
[0:] shutdown TLS session
[0:] close TLS session
[0:] close secure transport client
Thread started: #29
[0:] removing module "audiounit_ios"
[0:] destroying useless vout
[0:] removing module "ios"
[0:] deleting display
=================================================================
Native Crash Reporting
=================================================================
Got a segv while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
=================================================================
Native stacktrace:
=================================================================
0x104b840d5 - /Users/sethrogatzki/Library/Developer/CoreSimulator/Devices/B2E88654-02D0-4800-97A4-7043C512985B/data/Containers/Bundle/Application/0E9E69A6-CDC8-4FDD-84DC-81F6A338A679/VideoViewError.iOS.app/VideoViewError.iOS : mono_dump_native_crash_info
0x104b78bce - /Users/sethrogatzki/Library/Developer/CoreSimulator/Devices/B2E88654-02D0-4800-97A4-7043C512985B/data/Containers/Bundle/Application/0E9E69A6-CDC8-4FDD-84DC-81F6A338A679/VideoViewError.iOS.app/VideoViewError.iOS : mono_handle_native_crash
0x104b8aa09 - /Users/sethrogatzki/Library/Developer/CoreSimulator/Devices/B2E88654-02D0-4800-97A4-7043C512985B/data/Containers/Bundle/Application/0E9E69A6-CDC8-4FDD-84DC-81F6A338A679/VideoViewError.iOS.app/VideoViewError.iOS : mono_sigsegv_signal_handler_debug
0x121efee2d - /usr/lib/system/libsystem_platform.dylib : _sigtramp
0x7 - Unknown
=================================================================
Basic Fault Address Reporting
=================================================================
Memory around native instruction pointer (0x122b6796e):0x122b6795e 18 80 00 00 89 d8 5b 41 5e 5d c3 90 55 48 89 e5 ......[A^]..UH..
0x122b6796e 48 81 3f 5a 54 55 4d 75 73 8b 47 0c 89 c1 81 e1 H.?ZTUMus.G.....
0x122b6797e c0 01 00 00 83 f9 40 74 6b 0f ba e0 0e 72 6d 48 ......@tk....rmH
0x122b6798e 8d 57 27 48 83 e2 f8 48 8b 0a f6 c1 02 75 45 4c .W'H...H.....uEL
=================================================================
Managed Stacktrace:
=================================================================
at <unknown> <0xffffffff>
at Native:LibVLCMediaPlayerSetNsobject <0x0012d>
at LibVLCSharp.Shared.MediaPlayer:set_NsObject <0x000a2>
at LibVLCSharp.Platforms.iOS.VideoView:Detach <0x00102>
at LibVLCSharp.Platforms.iOS.VideoView:Dispose <0
x000b2>
at Foundation.NSObject:Dispose <0x00074>
at Xamarin.Forms.Platform.iOS.ViewRenderer`2:Dispose <0x0021a>
at Foundation.NSObject:Dispose <0x00074>
at Xamarin.Forms.Platform.iOS.VisualElementPackager:Dispose <0x002c5>
at Xamarin.Forms.Platform.iOS.VisualElementPackager:Dispose <0x00071>
at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1:Dispose <0x0024a>
at Foundation.NSObject:Dispose <0x00074>
at Xamarin.Forms.Platform.iOS.DisposeHelpers:DisposeModalAndChildRenderers <0x0030f>
at <Xamarin-Forms-INavigation-PopModalAsync>d__25:MoveNext <0x008d2>
at MoveNextRunner:InvokeMoveNext <0x000ab>
at System.Threading.ExecutionContext:RunInternal <0x00585>
at System.Threading.ExecutionContext:Run <0x00092>
at MoveNextRunner:Run <0x001aa>
at System.Threading.Tasks.AwaitTaskContinuation:InvokeAction <0x00093>
at System.Threading.Tasks.AwaitTaskContinuation:RunCallback <0x00153>
at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation:Run <0x0013a>
at
System.Threading.Tasks.Task:FinishContinuations <0x006a6>
at System.Threading.Tasks.Task:FinishStageThree <0x0015a>
at System.Threading.Tasks.Task`1:TrySetResult <0x0022a>
at System.Threading.Tasks.TaskCompletionSource`1:TrySetResult <0x00092>
at System.Threading.Tasks.TaskCompletionSource`1:SetResult <0x0007a>
at <>c__DisplayClass33_0:<DismissViewControllerAsync>b__0 <0x00082>
at SDAction:Invoke <0x00154>
at SDAction:Invoke <0x0010a>
at <unknown> <0xffffffff>
at UIKit.UIApplication:UIApplicationMain <0x00254>
at UIKit.UIApplication:Main <0x00172>
at VideoViewError.iOS.Application:Main <0x00092>
at <Module>:runtime_invoke_void_object <0x00198>
=================================================================
Environment
- OS: iOS
- Version: 15.0
- Device: iPhone 8
- LibVLC version and architecture: LibVLC.iOS 3.3.17, x64
- LibVLCSharp version: LibVLCSharp.Forms 3.6.1
Possible fixes
VideoPlayerViewModel Lines 62, 63, 104 and 105 are the most suspect.