Swiftgram / TDLibKit

Native Swift wrapper for Telegram's TDLib. Available on iOS, macOS, watchOS, tvOS and visionOS.
MIT License
101 stars 23 forks source link

App crash after closing session #28

Closed k0ry closed 1 year ago

k0ry commented 1 year ago

Hello, after going to authorizationStateClosed and trying to create a new instance of TdClientImpl I receive SIGABRT with logging information "Receive is called after Client destroy, or simultaneously from different threads. Fatal error: Attempted to read an unowned reference but object 0xXXXXX was already deallocated".

Deinit of TdClientImpl calls func close(), after that in run func used unowned self - leading to SIGABRT. What can I do in this situation? May be rewrite func something like this?:

public func run(updateHandler: @escaping CompletionHandler) { self.updateHandler = updateHandler createClientIfNeeded()

    tdlibMainQueue.async { [weak self] in
        guard !self.isClientDestroyed else { return }
        guard let self = self else {return}
        while (!self.stopFlag) {
            guard
                let res = td_json_client_receive(self.client, 10),
                let data = String(cString: res).data(using: .utf8)
            else {
                continue
            }
            self.logger?.log(String(cString: res), type: .receive)
            self.queryResultAsync(data)
        }
    }
}
neoromantic commented 1 year ago

Got into same error. Am I wrong or is the td_json_client old and unsupported? Is this lib supported? Did you find a solution here?