macOS: You released the media player before ensuring that it is stopped
Using SwiftUI+VLCKit to play video on macOS from a local Enigma2 STB.
Working fine until I defocus the window, or play another URL, at which point I get a crash with error:
2020-06-30 10:43:43.686206+0100 MailMac[57501:392918] creating player instance using shared library
2020-06-30 10:43:43.690895+0100 MailMac[57501:392918] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x6000036b8640> F8BB1C28-BAE8-11D6-9C31-00039315CD46
2020-06-30 10:43:43.746455+0100 MailMac[57501:392918] HALC_ShellDriverPlugIn::Open: Can't get a pointer to the Open routine
Attempt to play: http://<redacted>:8001/1:0:19:44E:3E9:2174:EEEE0000:0:0:0:
Playing http://<redacted>:8001/1:0:19:44E:3E9:2174:EEEE0000:0:0:0:
2020-06-30 10:43:47.045739+0100 MailMac[57501:393105] Metal API Validation Enabled
2020-06-30 10:44:09.631348+0100 MailMac[57501:392918] *** Assertion failure in -[VLCMediaPlayer dealloc], /Users/videolan/builds/NYJGMvSd/0/videolan/VLCKit/Sources/VLCMediaPlayer.m:321
2020-06-30 10:44:09.633960+0100 MailMac[57501:392918] [General] An uncaught exception was raised
2020-06-30 10:44:09.634039+0100 MailMac[57501:392918] [General] You released the media player before ensuring that it is stopped
2020-06-30 10:44:09.634136+0100 MailMac[57501:392918] [General] (
0 CoreFoundation 0x00007fff285f636f __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007fff66ff5a56 objc_exception_throw + 48
2 CoreFoundation 0x00007fff2861ef12 +[NSException raise:format:arguments:] + 88
3 Foundation 0x00007fff2afd2739 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
4 VLCKit 0x00000001083973c5 -[VLCMediaPlayer dealloc] + 477
5 libobjc.A.dylib 0x00007fff66ff182b _ZL27object_cxxDestructFromClassP11objc_objectP10objc_class + 83
6 libobjc.A.dylib 0x00007fff66fea487 objc_destructInstance + 94
7 libobjc.A.dylib 0x00007fff66fea3f2 _objc_rootDealloc + 62
8 VLCKit 0x000000010838cb99 __destroy_helper_block_e8_32s40s + 24
9 libsystem_blocks.dylib 0x00007fff6827f605 _Block_release + 128
10 libdispatch.dylib 0x00000001078e54dc _dispatch_client_callout + 8
11 libdispatch.dylib 0x00000001078f55e9 _dispatch_main_queue_callback_4CF + 1107
12 CoreFoundation 0x00007fff285b9593 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
13 CoreFoundation 0x00007fff2857baa7 __CFRunLoopRun + 2119
14 CoreFoundation 0x00007fff2857abea CFRunLoopRunSpecific + 534
15 HIToolbox 0x00007fff26f61dd0 RunCurrentEventLoopInMode + 292
16 HIToolbox 0x00007fff26f61bc9 ReceiveNextEventCommon + 709
17 HIToolbox 0x00007fff26f618ec _BlockUntilNextEventMatchingListInModeWithFilter + 64
18 AppKit 0x00007fff254b7e2b _DPSNextEvent + 877
19 AppKit 0x00007fff254b6659 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1352
20 AppKit 0x00007fff254a8b4b -[NSApplication run] + 586
21 AppKit 0x00007fff2547ca58 NSApplicationMain + 790
22 SwiftUI 0x00007fff34078ed4 $s7SwiftUI6runAppys5NeverOSo21NSApplicationDelegate_pFTf4e_nAA07TestingdG0C_Tg5 + 100
23 SwiftUI 0x00007fff3483cc04 $s7SwiftUI6runAppys5NeverOxAA0D0RzlF + 164
24 SwiftUI 0x00007fff3443806f $s7SwiftUI3AppPAAE4mainyyFZ + 63
25 MailMac 0x0000000107647d11 $s7MailMac11E2PlayerAppV5$mainyyFZ + 33
26 MailMac 0x0000000107647d94 main + 20
27 libdyld.dylib 0x00007fff68227c71 start + 1
28 ??? 0x0000000000000003 0x0 + 3
)
2020-06-30 10:44:09.648335+0100 MailMac[57501:392918] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'You released the media player before ensuring that it is stopped'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff285f636f __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007fff66ff5a56 objc_exception_throw + 48
2 CoreFoundation 0x00007fff2861ef12 +[NSException raise:format:arguments:] + 88
3 Foundation 0x00007fff2afd2739 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
4 VLCKit 0x00000001083973c5 -[VLCMediaPlayer dealloc] + 477
5 libobjc.A.dylib 0x00007fff66ff182b _ZL27object_cxxDestructFromClassP11objc_objectP10objc_class + 83
6 libobjc.A.dylib 0x00007fff66fea487 objc_destructInstance + 94
7 libobjc.A.dylib 0x00007fff66fea3f2 _objc_rootDealloc + 62
8 VLCKit 0x000000010838cb99 __destroy_helper_block_e8_32s40s + 24
9 libsystem_blocks.dylib 0x00007fff6827f605 _Block_release + 128
10 libdispatch.dylib 0x00000001078e54dc _dispatch_client_callout + 8
11 libdispatch.dylib 0x00000001078f55e9 _dispatch_main_queue_callback_4CF + 1107
12 CoreFoundation 0x00007fff285b9593 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
13 CoreFoundation 0x00007fff2857baa7 __CFRunLoopRun + 2119
14 CoreFoundation 0x00007fff2857abea CFRunLoopRunSpecific + 534
15 HIToolbox 0x00007fff26f61dd0 RunCurrentEventLoopInMode + 292
16 HIToolbox 0x00007fff26f61bc9 ReceiveNextEventCommon + 709
17 HIToolbox 0x00007fff26f618ec _BlockUntilNextEventMatchingListInModeWithFilter + 64
18 AppKit 0x00007fff254b7e2b _DPSNextEvent + 877
19 AppKit 0x00007fff254b6659 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1352
20 AppKit 0x00007fff254a8b4b -[NSApplication run] + 586
21 AppKit 0x00007fff2547ca58 NSApplicationMain + 790
22 SwiftUI 0x00007fff34078ed4 $s7SwiftUI6runAppys5NeverOSo21NSApplicationDelegate_pFTf4e_nAA07TestingdG0C_Tg5 + 100
23 SwiftUI 0x00007fff3483cc04 $s7SwiftUI6runAppys5NeverOxAA0D0RzlF + 164
24 SwiftUI 0x00007fff3443806f $s7SwiftUI3AppPAAE4mainyyFZ + 63
25 MailMac 0x0000000107647d11 $s7MailMac11E2PlayerAppV5$mainyyFZ + 33
26 MailMac 0x0000000107647d94 main + 20
27 libdyld.dylib 0x00007fff68227c71 start + 1
28 ??? 0x0000000000000003 0x0 + 3
)
libc++abi.dylib: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'You released the media player before ensuring that it is stopped'
terminating with uncaught exception of type NSException
(lldb)
Code
import SwiftUI
import VLCKit
struct MediaVideoPlayer: NSViewRepresentable {
var url: String
let mediaPlayer = VLCMediaPlayer()
func makeNSView(context: Context) -> NSView {
print("Attempt to play: \(self.url)")
let controller = NSView()
mediaPlayer.drawable = controller
let uri = URL(string: self.url)
let media = VLCMedia(url: uri!)
mediaPlayer.media = media
mediaPlayer.play()
print("Playing \(self.url)")
return controller
}
func updateNSView(_ uiView: NSView, context: NSViewRepresentableContext<MediaVideoPlayer>) {
}
func playPause() {
mediaPlayer.isPlaying ? mediaPlayer.pause() : mediaPlayer.play()
}
func stop() {
if (isPlaying()){
mediaPlayer.stop();
}
}
func isPlaying() -> Bool {
return mediaPlayer.isPlaying
}
}