Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • VLCKit VLCKit
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 108
    • Issues 108
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 9
    • Merge requests 9
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • VideoLAN
  • VLCKitVLCKit
  • Issues
  • #576

Closed
Open
Created Jan 05, 2022 by Jaidyn-B@Jaidyn-B

EXC_BAD_ACCESS crash calling VLCMediaPlayer.play() for the second time.

I am trying to show a MxPEG stream within a SwiftUI app. I am using MobileVLCKit version ~> 3.3.0 in my Podfile. Here is my UIViewRepresentable code:

import SwiftUI
import MobileVLCKit

struct VLCPlayerView: UIViewRepresentable {

    var url: String
    
    static let vlcMediaPlayer = VLCMediaPlayer()
    

    func makeUIView(context: Context) -> UIView {
        print("Making UIView")
        let controller = UIView()
        
        VLCPlayerView.vlcMediaPlayer.drawable = controller
        
        guard let uri = URL(string: url) else {
            fatalError("Could not parse URL string.")
        }
        
        let media = VLCMedia(url: uri)
        media.addOption(":avformat-format=mxg")
        
        VLCPlayerView.vlcMediaPlayer.media = media
        VLCPlayerView.vlcMediaPlayer.play()

        return controller
    }

    func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<VLCPlayerView>) {}
    
    static func dismantleUIView(_ uiView: UIView, coordinator: Self.Coordinator) {
        stop()
    }
    
    static func stop() {
        
        if (isPlaying()) {
            print("Stopping playback")
            VLCPlayerView.vlcMediaPlayer.stop()
        }
    }
    
    static func isPlaying() -> Bool {
        return VLCPlayerView.vlcMediaPlayer.isPlaying
    }
}

And it's displayed in a VStack like this:

ZStack {
            VStack {
                DetailHeader(
                    text: "Camera Video",
                    isLandscape: isLandscape(orientation: orientation))
                
                ZStack {
                    ZStack {
                        Color(.black).frame(height: 200, alignment: .center)
                        ProgressView().scaleEffect(1.5, anchor: .center).progressViewStyle(CircularProgressViewStyle(tint: .gray))
                    }
                    
                    VLCPlayerView(url: cameraURL)
                        .frame(height: 200, alignment: .center)
                }
            }
        }

I arrived at this code from the example in this thread here.

Opening the stream for the first time works, however navigating to the previous screen and coming back causes an EXC_BAD_ACCESS crash. I've tried a bunch of different workarounds for this, including loading the VLCMediaPlayer from a ViewModel and passing it to the VLCPlayerView directly, but all of them crash after trying to load the camera feed a second time.

Stack trace is here:

Screen_Shot_2022-01-05_at_9.45.10_am

And the console output is here:

Screen_Shot_2022-01-05_at_9.45.22_am

Running on an M1 Mac mini with XCode version 13.2.1.

Clearly it's holding a reference to something that's being released, but I can't find it. Zombie objects are turned on in XCode Scheme settings, and Address Sanitization is on as well.

Any help would be appreciated.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking

VideoLAN code repository instance