opentok / opentok-ios-sdk-samples-swift

Sample applications using the OpenTok iOS SDK in Swift
https://tokbox.com/
MIT License
137 stars 65 forks source link

Session connect memory error access #190

Closed Ibernato93 closed 1 year ago

Ibernato93 commented 1 year ago

Describe the bug I followed the OpenTok tutorial for swift on the official site, but I get an error:

memory read failed for 0x200 
Thread 11: EXC_BAD_ACCESS (code=1, address=0x200)

when I run

var error: OTError?
session?.connect(withToken: token, error: &error)

This is additional info in the log

***** OpenTok iOS SDK | Version/Revision: ios-2.24.1/808d4b23939b110853876902f97217beca087ee3 | Library built on: Dec 15 2022 | Copyright 2022 Vonage | https://www.vonage.com/legal/communications-apis/terms-of-use/
2023-02-07 18:53:02.096994+0100 IDToolsOrchestratorIQP[3577:149098] [Client] Updating selectors after delegate addition failed with: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service with pid 92 named com.apple.commcenter.coretelephony.xpc was invalidated from this process." UserInfo={NSDebugDescription=The connection to service with pid 92 named com.apple.commcenter.coretelephony.xpc was invalidated from this process.}

I am building opentok in a static framework and integrating it with cocoapods in my app.

This is my class

import UIKit
import OpenTok

class ViewController: UIViewController, UINavigationControllerDelegate{
    private var session: OTSession?
    private var publisher: OTPublisher?
    private var subscriber: OTSubscriber?

    override func viewDidLoad() {
        super.viewDidLoad()
        navigationController?.delegate = self
        if (!requestCameraPermission() && !requestAudioPermission()){
            return
        }

        doConnect(
            apiKey: "", sessionID: "", token: "")
    }

    fileprivate func doConnect(apiKey:String, sessionID:String, token:String) {
        session = OTSession(apiKey: apiKey, sessionId: sessionID, delegate: self)
        Log.debug("session create")
        var error: OTError?
        session?.connect(withToken: token, error: &error)
        Log.debug("session.connect")
        if error != nil {
            Log.debug("doConnect - error not nil")
            return
        }
        Log.debug("session.connect complete")
    }

    private func checkPermissions() -> Bool{
        return AVAudioSession.sharedInstance().recordPermission == .granted && AVCaptureDevice.authorizationStatus(for: .video) == .authorized
    }

    private func requestCameraPermission() -> Bool{
        var permission = false

        AVCaptureDevice.requestAccess(for: .video, completionHandler: { (granted: Bool) in
            if granted {
                permission = true
            } else {

                permission = false
            }
        })

        return permission
    }

    private func requestAudioPermission() -> Bool{
        var permission = false
        AVAudioSession.sharedInstance().requestRecordPermission({ (granted) in
                       if granted {

                           permission = true
                       } else {
                           DispatchQueue.main.async {
                               self.closeViewControllerOnError(error: .ERROR_PERMISSION_DENIED)
                           }
                           permission = false
                       }
                   })
        return permission
    }

}

// MARK: - OTSession delegate callbacks
extension ViewController: OTSessionDelegate {
    func sessionDidConnect(_ session: OTSession) {
        Log.debug("Session connected")
    }

    func sessionDidDisconnect(_ session: OTSession) {
        Log.debug("Session disconnected")
    }

    func session(_ session: OTSession, streamCreated stream: OTStream) {
        Log.debug("Session streamCreated: \(stream.streamId)")
    }

    func session(_ session: OTSession, streamDestroyed stream: OTStream) {
        Log.debug("Session streamDestroyed: \(stream.streamId)")

    }

    func session(_ session: OTSession, didFailWithError error: OTError) {
        Log.debug("session Failed to connect: \(error.localizedDescription)")
    }

}

// MARK: - OTPublisher delegate callbacks
extension ViewController: OTPublisherDelegate {
    func publisher(_ publisher: OTPublisherKit, streamCreated stream: OTStream) {
        Log.debug("Publishing")
    }

    func publisher(_ publisher: OTPublisherKit, streamDestroyed stream: OTStream) {
    }

    func publisher(_ publisher: OTPublisherKit, didFailWithError error: OTError) {
        Log.debug("Publisher failed: \(error.localizedDescription)")
    }
}

// MARK: - OTSubscriber delegate callbacks
extension ViewController: OTSubscriberDelegate {
    func subscriberDidConnect(toStream subscriberKit: OTSubscriberKit) {
        Log.debug("Suvscriber Did connect")
    }

    func subscriber(_ subscriber: OTSubscriberKit, didFailWithError error: OTError) {
        Log.debug("Subscriber failed: \(error.localizedDescription)")
    }
}

Devices and library:

Ibernato93 commented 1 year ago

UPDATE

I found that the cause of the problem is because I use this openssl dependency in the pod pod 'OpenSSL-Universal', '1.1.1900' I need this dependency for another project. Can you solve?

@robjperez @v-kpheng @pardel @abdulajet

v-kpheng commented 1 year ago

Nice troubleshooting, @Ibernato93 :-) Issue has been added to our current sprint: https://jira.vonage.com/browse/OPENTOK-49687.

Ibernato93 commented 1 year ago

@v-kpheng Perfect! Looking forward to your next release :)

sumit-kasaudhan commented 1 year ago

Facing crash when session?.connect(withToken: token, error: &error) is called on version 2.24.0 onward. With earlier version of vonage app is working fine .

I have BoringSSL sdk in my app . Crash shows- bssl::ssl_cert_clear_certs bssl::internal::Deleter >::reset(stack_st_CRYPTO_BUFFER*)

Looks like this is related.

czoli1976 commented 1 year ago

@Ibernato93 did you try with the latest release? 2.25.1 ?

Ibernato93 commented 1 year ago

@Ibernato93 did you try with the latest release? 2.25.1 ?

This version fix this problem?

v-kpheng commented 1 year ago

@Ibernato93 did you try with the latest release? 2.25.1 ?

This version fix this problem?

Yes, iOS SDK 2.25.1 should fix the issue for you.

Ibernato93 commented 1 year ago

Hi @v-kpheng , sorry for the delay but only now I got to test. I can't find version 2.25.2 on cocoapods, could you post it there?

v-kpheng commented 1 year ago

Hi @v-kpheng , sorry for the delay but only now I got to test. I can't find version 2.25.2 on cocoapods, could you post it there?

It's available as cocoapod OTXCFramework.

Ibernato93 commented 1 year ago

@v-kpheng , this new version 2.25.2 use tensorflow? I have this errors duplicate symbol '_TfLiteDelegateCreate' in: /Users/username/Library/Developer/Xcode/DerivedData/DemoSwift-efaeqenaoaskwthbcuwzedrvtroq/Build/Products/Debug-iphoneos/XCFrameworkIntermediates/OTXCFramework/OpenTok.framework/OpenTok(OpenTok-arm64-master.o)

In my pod i have 'TensorFlowLiteSwift', '2.6.0'

Version 2.25.1 work without problem.

Fix 2.25.2 please!

v-kpheng commented 1 year ago

@Ibernato93, yes. It looks like you're using it as well, given the duplicate symbols errors. We're looking into that issue now.

Ibernato93 commented 1 year ago

Thanks :)