Currently trying to translate between Chinese and English using Google's MLKit Translation API. However when I translate from English to Chinese, and then Chinese back to English, it results in the application crashing with the error pointer being freed was not allocated. Here are some examples of what happens.
Example1
In English:"Hello how are you today"error for object 0x...: pointer being freed was not allocatedExample2
In English:"Hello"Translate OK:"你好"In Chinese:"你好"error for object 0x...: pointer being freed was not allocatedExample3
In English:"Hello"Translate OK:"你好"In Chinese:"你好"Translate OK:"Hello"In English:"How are you"error for object 0x...: pointer being freed was not allocatedAt this point I'm not even sure what is causing this issue and no idea how I can go about fixing it.
Here are the main components of the code that performs the translation.
public func translate(native: String, reverse: Bool = false, completion: @escaping () -> Void) { print("REVERSE: \(reverse)") var translator: Translator! { reverse ? translatorToNative : translatorToForeign } print("") guard let translatorForDownloading = translator else { print("Translator not initialized") return } print("THERE") translatorForDownloading.translate(native) { translatedText, error in guard error == nil else { print("Failed with error \(error!)") return } print("TRANSLATED: \(translatedText ?? "")") completion() } }}import SwiftUI// When pause in recording is detected, save the content in history private func saveTranscription(completion: @escaping() -> Void) { print("NATIVE: \(recognizer.transcript)") translator.translate(native: recognizer.transcript, reverse: !speakerPicker) { let newHistory = Conversation.History(speaker: speaker, content: recognizer.transcript) conversation.history.append(newHistory) completion() } }}The translate function is receiving text but I have no idea how to resolve this memory issue.
I'm just trying to make sure that I am able to translate between Chinese and English back and forth like a conversation. Right now one, two, or three sentences in, the issue will occur.