-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
objective_c throws '_isValidObject(ptr)': is not true #1340
Comments
I'm guessing it's the completion handler that throws the error. There are a few places where the handler is being called in your swift function. Do you know which code path you're hitting? I can't tell much from the Dart stack trace. Anyway, that assertion is designed to catch cases where we try to use an ObjC object in Dart when it's already been freed. This used to be a big issue for listener blocks, because they are called asynchronously, so their arguments may be freed before the callback is run. That bug is fixed now, but the fix hasn't been published yet. Which version of ffigen are you using? |
Here is the private func savePhoto(_ photo: AVCapturePhoto, name: String?, completionHandler handler: @escaping (String?, (any Error)?) -> Void) {
do {
if let data = photo.fileDataRepresentation() {
let fileManager = FileManager.default
guard let documentUrl = try? fileManager.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true) else {
throw CameraError.saveUrlNil
}
let photosUrl = documentUrl.appendingPathComponent("Photos")
if !fileManager.fileExists(atPath: photosUrl.path) {
try fileManager.createDirectory(at: photosUrl, withIntermediateDirectories: true)
}
let dataUri = photosUrl.appendingPathComponent(UUID().uuidString).appendingPathExtension("JPG")
try data.write(to: dataUri, options: .atomic)
debugPrint("saved uri \(dataUri.path)")
PHPhotoLibrary.shared().performChanges() {
let creationRequest = PHAssetCreationRequest.forAsset()
let options = PHAssetResourceCreationOptions()
options.originalFilename = name
creationRequest.addResource(with: .photo, data: data, options: options)
} completionHandler: { success, error in
if let error {
handler(nil, error)
} else {
handler(dataUri.path, nil)
}
}
} else {
throw CameraError.savePhotoNil
}
} catch {
handler(nil, error)
}
} I'm using ffigen: 12.0.0 |
Ok, then this is a dupe of #835. if you're on ffigen 12, you don't have the fix yet. I'm planning to publish ffigen 13 later this week, so just wait for that (or add it as a git dependency if you want to try the fix now). The fix involves generated ObjC code, in addition to the generated Dart code. So you'll need to include the generated ObjC file in your app/plugin build. |
ffigen 13.0.0 is published |
Should I change the plugin to plugin_ffi and include the generated .m file to CMakeList? Or just add the .m file to the Classes folder? |
Either should work. You just have to include the .m file in the build somehow. |
I have written a method with Swift and use ffigen to generate the dart bindings.
When I call the metod from Dart, the method throws an error like this.
Here is the Swift method.
Here is the Dart caller.
The text was updated successfully, but these errors were encountered: